+ 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

29th Mar 2018, 4:38 AM
PRITAM CHAKRABORTY
PRITAM CHAKRABORTY - avatar
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.
29th Mar 2018, 4:58 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
int factorial(int num) { if (num == 1) /* base case */ return (1); else return (num * factorial(num - 1));
10th Dec 2021, 5:43 PM
Medhat Mohamed Ibrahim Abu Mandour
Medhat Mohamed Ibrahim Abu Mandour - avatar
0
looks like you already found a fix in your code.
29th Mar 2018, 9:12 AM
Jared Bird
Jared Bird - avatar
0
fact
14th Oct 2021, 3:35 PM
Nubia Damaris Lopez Castillo
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); }
23rd Sep 2022, 4:53 PM
ABDUL WAHAB
0
return fact are the answers at the given blank spaces
18th Feb 2023, 7:00 AM
Jembere Guta
Jembere Guta - avatar