Question PSC-LOOP-0002
EasyWhat will be the output of the following pseudocode?
Integer sum = 0
for (each i from 1 to 5)
sum = sum + i
end for
Print sum
- A.
5
- B.
10
- C.
Show answer and explanation
Answer: C
The loop adds 1 + 2 + 3 + 4 + 5 = 15.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Loops question
What will be the output of the following pseudocode?
Integer sum = 0
for (each i from 1 to 5)
sum = sum + i
end for
Print sum
5
10
Answer: C
The loop adds 1 + 2 + 3 + 4 + 5 = 15.
15
20