Open In App

Capgemini | Pseudocode Questions | Question 2

Which of the following series will be printed by the given pseudocode? 

Integer a, b, c 
Set b = 4, c = 5 
for(each a from 2 to 4) 
  print c 
  b = b - 1 
  c = c + b 
end for

(A)



5 8 10

(B)



1 3 6

(C)

8 9 10

(D)

3 6 9

Answer: (A)
Explanation:

Firstly variables a, b, and c are initialized, then b and c are assigned values 4 and 5 respectively. 
Now run a loop from 2 to 4, in each iteration b is decremented by 1, and c is incremented by b. 
In the first iteration print c = 5 value of b is decremented by 1 i.e. b = 3, c is incremented by b i.e. c = 5 
In the second iteration print c = 8 value of b is decremented by 1 i.e. b = 2, c is incremented by b i.e. c = 8 
In the third iteration print c = 10 value of b is decremented by 1 i.e. b = 1, c is incremented by b i.e. c = 10 

Thus the final series is 5, 8, 10

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :
Uncategorized