Consider the following program segment in which the statements are jumbled. Choose the correct order of statements to calculate and return the factorial of 4.

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

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

Consider the following program segment in which the statements are jumbled.
Choose the correct order of statements to calculate and return the factorial of 4.

for(k = 1; k <= 4; k++) → 1
return fa; → 2
long fa = 1, k; → 3
fa *= k; → 4
Show SolutionHide Solution↓

3, 1, 4, 2

Reason — To calculate and return the factorial of 4 using a loop, we must follow the proper sequence of statements:

  1. long fa = 1, k; – This is the declaration and initialization of variables fa and k.
  2. for(k = 1; k <= 4; k++) – This sets up a loop to run from 1 to 4.
  3. fa *= k; – This multiplies the current value of fa by k during each iteration.
  4. return fa; – This returns the final calculated factorial value.

So, the correct order is: 3, 1, 4, 2, which correctly calculates and returns the factorial.

← Previous questionNext question →

Browse the free Computer Applications sample bank