Mathematics 1201: Programming in C First Midterm Test, Answer Sheet Prof. Wickerhauser In Problems 1--3 below, find the value of `x' after all of the following statements are executed: Problem 1. int x = 11, y = 23; x /= y%4; ANSWER 1: x = 3 Problem 2. int i, x; for ( i = 1, x = 1; i<=10; i<<=1 ) x += 0xC; ANSWER 2: x = 49 Problem 3. #define E 2.71828 int x; x = E + 0.5; ANSWER 3: x = 3 Problem 4. Suppose that A and B are int's with A = 3 and B = -1. What is the value of the following expression: ++A + B++ ANSWER 4: ++A + B++ == 3 Problem 5. Suppose that A and B are int's with A = 1 and B = -1. What will the following code print: if ( A<0 || B<0 ) if ( B>0 ) printf("1\n"); else printf("2\n"); else printf("3\n"); ANSWER 5: 2 Problem 6: Write a complete ANSI C program to prompt for an integer between 1 and 99, inclusive, and then print the sum of all the odd positive integers less than or equal to it. ANSWER 6: #include main( void ) { int n, i, sum; printf("Enter a number between 1 and 99, inclusive: "); scanf("%d", &n); if(n<1 || n>99) return(1); for(i=1; i<=n; i+=2) sum += i; printf("%d\n", sum); return(0); }