Question: Pseudocode PROGRAM // student provides algorithm to print the column-header line FOR x := 1 TO 12 BY 1 // print row-header PRINT x //
Pseudocode PROGRAM // student provides algorithm to print the column-header line FOR x := 1 TO 12 BY 1 // print row-header PRINT x // print row-of-(x+y)s FOR y := 1 to 12 BY 1 PRINT x+y END PRINT ENDL END STOP END Computational and Critical Thinking Questions 1. Notice that the output-formatting details are not given by the pseudocode, but are implicit in both the output requirements (the plan) and the example program output. How should the printf() used to implement the algorithmic step PRINT x be coded to right-justify the loop-control variable xs value in the required 2-character field? 2. (Continuing 1) You cannot use the very same format specifier when writing the printf() used to implement the algorithmic step PRINT x+y. Why? What should the printf() be? 3. The pseudocode requires the for(y)-statement to be statically-nested in the body of the for(x)-statement; that is, coded inside of the body of the for(x)-statement. What do the nested-loops mean? How many times does the for(y)-statement execute for each iteration of the for(x)-statement? ______ What is the value of y after the for(y)-statement terminates? ______ What is the value of x after the for(x)-statement terminates? ______ 4. Just for fun, re-write both of the for-statements as while-statements. Which is better, for-statements or while-statements in this particular situation? Why? What using-loop-statement pragmatics can you infer based on your answer to these questions? 5. How should the pseudocode (and obviously Problem6.c) change when the problem is changed to require the program user to input a value of n, a value that serves as an upper-bound of both x and y? Hints Dont forget to consider (1) the output-formatting requirements (XXX implies no x+y or x*y can greater than 999) and (2) the column-header line generating pseudocode would probably need to be different than the pseudocode you designed. 6. (Continuing 5) What is ( log10(n) + 1) when n = 50? ______ Hint Recall, the syntax x means next-lowest-integer-of x; for example, 3.51 = 3 and -3.01 = -4.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
