Midterms - Midterm Ex1 #include "stdafx.h"...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Midterm Ex1 #include "stdafx.h" #include "math.h" #include <iostream> using namespace std; void main(){ double n=300, d=1,x; while (n>=1){ d = 1+((1/n)*d); n--; } //cout<<d<<endl; cout<< "Enter integer:" ; cin>>x; cout<<pow(d,x); } Midterm Ex 2 #include "stdafx.h" #include <iostream> using namespace std; int main () { int x, i, j; cout<< "Enter a number in the interval [1,3]: " ; cin>>x; while ((x<1)||(x>3)) {cout<< "You entered an number out of range. Enter a number in the interval [1,3]: " ; cin>>x; } switch (x) { case 1: { for ( int i=0; i<5; i++) {cout<< "1" ;} cout<< "\n" ;} { for ( int i=0; i<5; i++) {cout<< "1" ;} cout<< "\n" ; } { for ( int i=0; i<5; i++) {cout<< "1" ;} cout<< "\n" ;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
{ for ( int i=0; i<5; i++) {cout<< "1" ;} cout<< "\n" ; } { for ( int i=0; i<5; i++) {cout<< "1" ;} cout<< "\n" ; } break ; case 2: for ( int i=0; i<10; i++) { j=i; if (j<6) { for ( int k=0; k<j; k++) { cout<< "2" ; } cout<< "\n" ; } else { for ( int k=0; k<(10-j); k++) { cout<< "2" ; } cout<< " \n" ; }} break ; case 3: for (i=1; i<10; i++) {j=i; j=10-j; cout<<j<< " " ;} cout<< "\n" ; for (i=2; i<10; i++) {j=i; j=10-j; cout<<j<< " " ;} cout<< "\n" ; for (i=3; i<10; i++) {j=i; j=10-j; cout<<j<< " " ;} cout<<
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Midterms - Midterm Ex1 #include &quot;stdafx.h&quot;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online