Consider the following recursive implementation to find the factorial of a number. Which of the lines is the base case?
int fact(int n)
{
if(n == 0)
return 1;
return n * fact(n - 1);
}
int main()
{
int n = 5;
int ans = fact(n);
printf("%d",ans);
return 0;
}
int fact(int n)
{
if(n == 0)
return 1;
return n * fact(n - 1);
}
int main()
{
int n = 5;
int ans = fact(n);
printf("%d",ans);
return 0;
}
A. return 1
B. return n * fact(n-1)
C. if(n == 0)
D. if(n == 1)
Answer: Option C
Join The Discussion