Skip to content

Commit 85527aa

Browse files
committed
recursive factorial
1 parent cffded4 commit 85527aa

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

prog.8.16.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdio.h>
2+
3+
int main (void)
4+
{
5+
unsigned int j;
6+
unsigned long int factorial (unsigned int n);
7+
8+
for ( j = 0; j < 11; ++j )
9+
printf ("%2u! = %lu\n", j, factorial(j));
10+
11+
return 0;
12+
}
13+
14+
// Recursive function to calculate the factorial of a positive integer
15+
unsigned long int factorial (unsigned int n)
16+
{
17+
unsigned long int result;
18+
19+
if ( n == 0 )
20+
result = 1;
21+
else
22+
result = n * factorial (n - 1);
23+
24+
return result;
25+
}

0 commit comments

Comments
 (0)