Skip to content

Commit a40a37d

Browse files
recursive
1 parent 5b21173 commit a40a37d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: functions/function_recursive.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
3+
int factorial(int num);
4+
5+
int main() {
6+
int x = 5;
7+
printf("The factorial of %d is %d.\n", x, factorial(x));
8+
return 0;
9+
}
10+
11+
int factorial(int num) {
12+
if (num == 1) { //base case
13+
return 1;
14+
}
15+
else {
16+
return(num * factorial(num - 1));
17+
}
18+
}

0 commit comments

Comments
 (0)