ProgrammingModerateAccenture · Cognizant GenC Next
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer n = 77, steps = 0, p
while (n >= 10)
p = 1
while (n > 0)
p = p * (n mod 10)
n = n / 10
end while
n = p
steps = steps + 1
end while
Print n, steps- A. 8 4
- B. 8 3
- C. 9 4
- D. 6 4
Correct answer: A. 8 4
Multiply the digits repeatedly: 77 → 49 → 36 → 18 → 8. That is 4 steps, ending at 8: 8 4.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (<< is left shift, | is bitwise OR, & is bitwise AND) Integer x = 0 for (each i from…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer mults = 0 Function…
- What will be the output of the following pseudocode? String s = "(()(()))()" Integer depth = 0, best = 0, pairs = 0 for (each i from 0 to…
- What will be the output of the following pseudocode? (^ is XOR, & is AND) Integer s = 0, x, p for (each i from 1 to 20) x = i p = 0 while…
- What will be the output of the following pseudocode? Integer P[4][4] = all 0 Integer A[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} for (each…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Function f(Integer n) if (n <…