PRASHNIKAप्रश्निका
‹ Back to the paper

Choose the correct option.

What is the output of the method fun() when the value of n=4?

Computer Science20222 marksMCQ
  • (i)24
  • (ii)72
  • (iii)120
  • (iv)ERROR
Show the code
void fun(int n)
{
    int i, f;
    for(i = 1, f = 1; i <= n; i++, f *= i);
    System.out.print(f);
}

Answer

Answer

AI

Correct option: (iii)

Answer: (iii) 120 f is multiplied after i is incremented: i=2 f=2, i=3 f=6, i=4 f=24, i=5 f=120, then the loop stops. It prints 120.
Methods

From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 26(a).