ProgrammingVery hardTCS Digital · Infosys InfyTQ
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Function gcd(Integer a, Integer b)
while (b != 0)
t = a mod b
a = b
b = t
end while
return a
end function
Integer i, j, c = 0
for (i = 1; i <= 30; i = i + 1)
for (j = i + 1; j <= 30; j = j + 1)
if (gcd(i, j) == 1)
c = c + 1
end if
end for
end for
Print c- A. 278
- B. 300
- C. 277
- D. 271
Correct answer: C. 277
For each j from 2 to 30 the number of i < j coprime to j is Euler's phi(j); the sum of phi(2..30) is 277.
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 = "{[()]}(()" Stack st Integer pops = 0, i Boolean ok = true for (i = 0; i <…
- What will be the output of the following pseudocode? Integer a[5] = {2, 5, 9, 14, 20}, i for (i = 1; i < 5; i = i + 1) a[i] = a[i] - a[i…
- What will be the output of the following pseudocode? Integer x = 0, i for (i = 1; i <= 10; i = i + 1) x = ((x << 1) ^ i) & 15 end for…
- What will be the output of the following pseudocode? Integer w[5][5], i, j for (i = 0; i < 5; i = i + 1) for (j = 0; j < 5; j = j + 1) if…
- What will be the output of the following pseudocode? String A = "AXYT", B = "AYZX" Integer L[5][5] = all 0, i, j for (i = 1; i <= 4; i = i…
- What will be the output of the following pseudocode? Integer n = 9, steps = 0 while (n != 1) if (n mod 2 == 0) n = n / 2 else n = 3 n + 1…