Factorial Using Recursion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>

int factorial(int n){
if (n==0) {
return 1;
} else {
return factorial(n-1)*n;
}
}

int main(int argc, const char * argv[]) {
int num = 5;
printf("%d\n", factorial(num));
return 0;
}