Consider the following pseudocode:
Find the initial value of a.
Find the final value of a.
Find the value of \text{OUTPUT}.
\text{START} \\ \text{SET } a = 9 \\ \text{SET sum = 0} \\ \text{WHILE } a \gt 3\\ \quad \text{sum = sum} + a\\ \quad a = a - 1 \\ \text{END WHILE} \\ \text{PRINT sum} \\ \text{END}
For each of the following pseudocodes:
Find the initial value of a.
Find the \text{OUTPUT} of the code.
\text{START} \\ \text{SET } a = 2 \\ \text{SET sum} = 0 \\ \text{WHILE a < 9} \\ \quad \text{sum = sum} + a \\ \quad a = a + 1 \\ \text{END WHILE} \\ \text{PRINT sum} \\ \text{END}
\text{START} \\ \text{SET } a = 3 \\ \text{SET sum} = 0 \\ \text{SET } n = 0 \\ \text{WHILE } a \lt 12 \\ \quad \text{sum = sum + a} \\ \quad a = a + 1 \\ \quad n = n + 1 \\ \text{END WHILE} \\ \text{PRINT sum / } n \\ \text{END}
Find the final value, n, for the following pseudocode:
\text{START} \\ \text{SET } a = 4 \\ \text{SET } n = 0 \\ \text{WHILE } a \gt 1 \\ \quad \text{sum = sum + a} \\ \quad a = a \, / \, 2 \\ \quad n = n + 1 \\ \text{END WHILE} \\ \text{END}
Determine the value that is printed at the end of the following pseudocodes:
\text{START} \\ \text{SET } a = 19 \\ \text{WHILE } a \gt 5 \\ \quad a = a - 1 \\ \text{END WHILE} \\ \text{PRINT } a \\ \text{END}
\text{START} \\ \text{SET } a = 1 \\ \text{WHILE } a \lt 24\\ \quad \text{PRINT } a \\ \quad a = a * 2 \\ \text{END WHILE} \\ \text{END}
\text{START} \\ \text{SET } a = 5 \\ \text{WHILE } a \lt 7 \\ \quad \text{PRINT } a \\ \quad a = a + 1 \\ \text{END WHILE} \\ \text{END}
\text{START} \\ \text{SET } a = 2 \\ \text{WHILE } a \lt 10 \\ \quad \text{PRINT } a \\ \quad a = a + 2 \\ \text{END WHILE} \\ \text{END}
\text{START} \\ \text{SET } a = 5 \\ \text{WHILE } a \lt 20 \\ \quad \text{PRINT } a \\ \quad a = a * 2 \\ \text{END WHILE} \\ \text{END}
Consider the algorithm represented by the flow chart:
Arrange the following lines of pseudocode in the correct order for the algorithm.
Step | Code |
---|---|
A | \text{WHILE } a \gt 4 |
B | \text{END WHILE} |
C | \text{PRINT } a |
D | \text{SET } a = 4 |
E | a = a - 1 |
Consider the algorithm represented by the flow chart:
Arrange the following lines of pseudocode in the correct order for the algorithm.
Step | Code |
---|---|
A | a = a + 1 |
B | \text{SET } a = 4 |
C | \text{WHILE } a \neq 5 |
D | \text{PRINT sum} |
E | \text{sum = sum} + a |
F | \text{END WHILE} |
G | \text{SET sum}=0 |
Consider the algorithm for finding the sum of the first n natural numbers represented by the flow chart.
Find the output of this algorithm if n=4.
Arrange the following lines of pseudocode for adding the first 50 natural numbers in the correct order for the algorithm.
Step | Code |
---|---|
A | \text{sum = } a + \text{sum} |
B | \text{PRINT sum} |
C | \text{SET } a=1 |
D | a=a+1 |
E | \text{GO TO LINE } 3 |
F | \text{SET sum}=0 |
G | \text{IF } a=50 \text{ THEN GO TO LINE } 7 |
The factorial of a non-negative integer n is given by n! = n \times (n-1) \times (n-2) \times .... \times 2 \times 1. For example, 5! = 5 \times 4 \times 3 \times 2 \times 1=120.
Consider the algorithm for finding n! represented by the flow chart:
Find the output of this algorithm if n=6.
Arrange the following lines of pseudocode in the correct order for finding 50!.
Step | Code |
---|---|
A | p = p * a |
B | a = a + 1 |
C | \text{PRINT } p |
D | \text{SET } a = 1 |
E | \text{IF } a=50 \text{ THEN GO TO LINE } 7 |
F | \text{SET } p=1 |
G | \text{GO TO LINE } 3 |