/* * SelfTest2 * Chapter 7 * John Stile */ 1. If a 'break' is in an 'if' that is inside a 'do/while' that is inside a 'case' that is inside a 'switch' running in a 'while' loop, where does program control go when the break is encoutnered? Answer1: while switch case '': 'do/while' if break Break takes to you out of the current loop. In this case it would leave the 'do/while', and go to the end of the case which would be the while loop at the top. 2. If we want a code block to execute one time and then, depending on the outcome of tha test, possibly run more times, what logical control strucite is appropriate? 'do/while' 3. What statement tells the program to go back to the beginning of the current loop without processing the remainder of the loop? Answer: continue 4. Write a program using for loop and the variables xx and xsqr to print the squares of the integers from 1 to 7. The following output is expected. 1 squared equals 1 2 squared equals 4 ... 7 squared equals 49 Answer: see SelfTest1.4.c 5. How many times will the following printf statement be exectued? #include int main(void) { short int aa; for(aa=1; aa>0; aa++) { printf("Hi"); } return 0; } Answer: Infinite 6. Write a program called factor.c that produces the produces the following factor output for a series of numbers using nested for loops. 1!= 1=1 2!= 2*1 = 2 3!= 3*2*1 = 6 ... 10!= 10*9*8*7*6*5*4*3*2*1 = 3628800 Answer: see factor.c 7. Write a program that asks an integer between 10 and 20 from the user. If the user enteres other values which do not satisfy the condition, prints an error message and asks for another number until the condition is met. Use a do...while loop and if...else structure. Answer: