We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cffded4 commit 85527aaCopy full SHA for 85527aa
prog.8.16.c
@@ -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