Fake Midterm Answers 1. There is a file, stuff.txt, in the directory ~sternfl/256F Write a command that will copy stuff.txt into your home directory. ( Answer: cp ~sternfl/256F/stuff.txt ~ ) 2. You are currently in your home directory. Your home directory contains the directory h5. Write a command that will make your current directory be h5. ( Answer: cd h5 ) 3. Suppose the computer is tasked with calculating the folowing expressions, what would the result be? (Answers in parenthesis) 1. 6 + 3 / 12 = ( 6 ) 2. 3 % 12 = ( 3 ) 3. 6 / 12.0 = ( 0.5 ) 4. Write a complete program that gets an integer, n, from the user and then prints out the previous 10 numbers in descending order. Each number should be printed on a line by itself: For example, If the user enters 20, then the program should print 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, in that order, on it's own line. Do NOT write ten printf statements. This program should only contain ONE printf statement in a loop. **** Begin Answer **** #include int main(){ int n; printf("Enter a number> "); scanf("%d", &n); for(int i = 0; i < 10; i++){ n--; printf("%d\n", n); } return 0; } **** End Answer **** 5. Play Computer: Consider the program below. Below the program, you can see the program's variables. Each variable has a box next to it. Directions: Values for a variable are to be written in the box for the variable. Work from left to right: When the program stores a value in a variable, write the value in the box for the variable to the right of the old values. When the computer prints a value, write it in the screen in the appropriate place (In this case, your answer for problem 6. ***** PROGRAM ***** #include int main(){ int sum = 0; for(int i = 1; i < 4; i++){ int v = 2 * i - 1; sum = sum + v; printf("%d %d\n", i, sum); } printf("Done\n"); return 0; } ***** VARIABLES ***** (Answers are in parentheses) sum: ( 0 1 4 9 ) i: ( 1 2 3 4 ) v: ( 1 3 5 ) 6. Referring to the above problem, what would the output screen look like? **** SCREEN **** 1 1 2 4 3 9 Done