ProgrammingModerateTCS NQT · Wipro
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)
Function count7(Integer n)
if (n == 0)
return 0
end if
Integer here = 0
if (n mod 10 == 7) here = 1
return here + count7(n / 10)
End Function
Print count7(771707), count7(70)- A. 3 0
- B. 4 2
- C. 5 1
- D. 4 1
Correct answer: D. 4 1
The function checks the last digit and recurses on the rest. 771707 has four 7's; 70 has one (its last digit 0 does not count, but the tens digit does). Output 4 1.
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? String s = "ABCAB" Integer cnt[26] = all 0, total = 0 for (each ch in s) cnt[ch] =…
- What will be the output of the following pseudocode? String s = "COMPUTER" Integer i = 0, j = length(s) - 1 while (i < j) while (i < j AND…
- What will be the output of the following pseudocode? Function isSub(String a, String b) // is b a subsequence of a? Integer j = 0 for…
- What will be the output of the following pseudocode? String s = "ABBACA" Stack st = empty for (each ch in s) if (st not empty AND top(st)…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6} Integer i = 0, j = 5 while (i < j) if (a[i] mod 2…
- What will be the output of the following pseudocode? Integer a[5] = {0, 1, 0, 3, 12}, k = 0 for (each i from 0 to 4) if (a[i] != 0)…