+ 5
Recursive function to calculate factorial of a no n.
in the lessons the code is given as follows int factorial(int n) { if (n==1) { return 1; } else { return n * factorial(n-1); } } but if n=0; what will be the output....but 0!=1; https://code.sololearn.com/ciR9qXseflpj/?ref=app
6 Antworten
+ 5
You are not suggested to post codes in Q&A section as question. Since it is a code, post it in code section.
+ 1
int factorial(int num) {
if (num == 1) /* base case */
return (1);
else
return (num * factorial(num - 1));
0
looks like you already found a fix in your code.
0
fact
0
Fill in the blanks to define a recursive function for calculating the factorial of n:
int fact(int n) {
if (n == 1)
return
1;
return n *
fact
(n - 1);
}
0
return
fact
are the answers at the given blank spaces