engineering recuitment RPSC Programmer Mock Test 2024 Programming and Data Structure Programming in C Function Recursion
The following C# code is supposed to calculate the factorial of a given number. However, there is an error in the code. Which of the following options correctly identifies and fixes the error?
public int Factorial(int num)
{
int result = 1;
for (int i = 0; i <= num; i++)
{
result *= i;
}
return result;
}
1
Change int i = 0 to int i = 1
2
Change result *= i to result *= i + 1
3
Change < num to <= num
4
Change result *= i to result *= i - 1
5
Question Not Attempted