‹ Back to the paper
Choose the correct option.
What is the method fun() performing?
- (i)Checking for Prime Numbers
- (ii)Product of odd numbers
- (iii)Factors of a number
- (iv)Finding the factorial
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
AICorrect option: (iv)
Answer: (iv) Finding the factorial
The method multiplies f by successive integers, the intended purpose being factorial (though as written it gives the factorial of n+1).
From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 26(b).