Name __________________________________________16.070 Exam #13/5/011. (5 points) Fill in the blank:To use printf or scanf, you must include the header file ____________________.2. (5 points) TRUE/FALSE When compiling nested IF ELSE statements, the compiler uses the indentation tomatch each ELSE with an IF.Circle one: TRUE FALSE3. In question 3, there are no deliberate syntax/typographical errors. Please mark yourfinal answer clearly. In order to receive partial credit, you must show your work.a) (8 points) Show the output and describe the behavior of the following statements foreach of the cases when x initially equals 0, 1 and –1:if ( x == 0 )printf(“A\n”);else if (x != 1)printf(“B\n”);else if (x < 1)printf(“C\n”);else if (x = -1)printf(“D\n”);else if (x)printf(“E\n”);b) (8 points) Show the output and describe the behavior of the following statements foreach of the cases when x initially equals 0, 1 and –1:int y;for (y=x; y>=0; y=x+1){printf(“%d ”,y);x--;}c) (8 points) Show the output and describe the behavior of the following statements foreach of the cases when x initially equals 0, 1 and –1:do{y=1;while ( ( y > 0 ) && ( x <= 0 ) ){printf(“x is equal to %d\n”,x); y--;}x++;} while ( x < 1 );4. (20 points) Design a program that will help Max the Mathematician manipulatenumbers. He needs a program to perform thefollowing tasks. First, ask a user for a positive integerinput, say n. Then, sum up all positive integers up toand including the user input, and tell the user theanswer; i.e., 1 + 2 + … + n. Next, compute the sum ofthe squares of these integers and tell the user theanswer; i.e., 12 + 2 2 + … + n 2. Finally, show the userthe factorial of each integer up to and including theuser input; i.e., 1!, 2!, … n!.Perform the first three steps of the software design process, up to and including definingthe algorithm(s). No code is required for this problem. Remember, modularity is avirtue.5. (16 points) What is the output of this program? No partial credit will be awardedwithout an explanation of your thought process. A trace would be acceptable.#include <stdio.h>int main(void){int y = 0;int z = 0;int total = 0;int iterated = 0;for (y=3; y >= 1; y--){for (z=2; z < y*2; z = z+2){total = total + 2;} /* end inner for */iterated++;} /* end outer for */printf(“The final value of iterated is:\n%d\n”, iterated);} /* end main */6. (15 points) Write a function that produces the following output:******…A passed parameter defines the number of lines to print. For example, if theparameter is 4, the output will look like this:**********The function's prototype isvoid draw_stars (int num);7. Given the code:1: #include <stdio.h>2: 3: int aa = 3;4: int f(int dd)5: {6: aa=5;7: return aa+dd;8: }9: 10: int main(void)11: {12: int aa=6, bb=5, cc=4, dd;13: 14: cc = aa + bb;15: {16: int cc=3, dd=2;17: 18: dd += aa + cc;19: aa %= dd;20: }21: dd = f(3);22: aa = cc + bb;23: 24: printf("aa = %d\n",aa);25: return 0;26: }a) (5 points) What is the value of aa printed when line 24 executes? Recall that x += 1translates into x = x + 1, and x %= 3 translates into x = x % 3.b) (10 points) On each of the four lines whose numbers are given below, a variable ischanged. For each line indicate:• which variable is being changed• on which line that variable is declared• for which lines the variable is in scope• for which lines the variable is visible• for which lines the variable is invisible• the value that is assigned to the variable:LineVariablechangedLine whereDECLAREDLines wherein SCOPELines whereVISIBLELines
View Full Document