MCQ Single Best Answer Moderate

QConsider the following program segment in which the statements are jumbled.

Choose the correct order of statements to calculate and return the factorial of 4.

  1. for (k=1; k<=4; k++)

  2. return fa;

  3. long fa = 1, k;

  4. fa *= k;

ID: #24168 ICSE Computer Application - Class X - 2025 PYQ 77 views
Question Info
#24168Q ID
ModerateDifficulty
ICSE Computer Application - Class X - 2025 PYQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 1, 2, 3, 4
  • B 3, 1, 4, 2
  • C 3, 1, 2, 4
  • D 1, 3, 2, 4
Correct Answer: Option B

Explanation

(b) 3, 1, 4, 2

Correct Order:

  1. long fa = 1, k; → (Initialize fa to store factorial)

  2. for (k=1; k<=4; k++) → (Loop through numbers 1 to 4)

  3. fa *= k; → (Multiply fa by k in each iteration)

  4. return fa; → (Return the computed factorial)

Share This Question

Challenge a friend or share with your study group.