Open In App

Capgemini | Pseudocode Questions | Question 6

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

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

(A)



5 4 3 2 1

(B)



0 1 3 6 10

(C)

2 5 8 9 10

(D)

0 0 0 0 0

Answer: (B)
Explanation:

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

Thus the final series is 0 1 3 6 10

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

Article Tags :
Uncategorized