Consider the following program segment in which the statements are jumbled . Choose the correct order of the statements to return the sum of first 10 natural…

ICSE Class 10 Computer Applications PYQ · 2025 Improvement · Section A

1(xx)1 Mark · 2025 · Section A · 2025 Improvement

Consider the following program segment in which the statements are jumbled. Choose the correct order of the statements to return the sum of first 10 natural numbers.

for(i=1; i<=10; i++)  → 1
return sum;           → 2
int sum = 0, i;       → 3
sum+=i;               → 4
Show SolutionHide Solution↓

3 1 4 2

Reason — To return the sum of first 10 natural numbers, we must follow the proper sequence of statements:

  1. int sum = 0, i; – Declare the variables sum and i, and initialize sum to 0.
  2. for(i=1; i<=10; i++) – Start the loop to go through numbers 1 to 10.
  3. sum+=i; – Add the current number i to sum during each loop iteration.
  4. return sum; – After the loop completes, return the total sum.
← Previous questionNext question →

Browse the free Computer Applications sample bank