Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 72e3bb2

Browse files
author
Sonny Li
committed
Week 3
1 parent c6e067f commit 72e3bb2

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎Programs/factorial.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Sonny Li
2+
// Intro to Programming in C
3+
4+
#include <stdio.h>
5+
6+
int factorial(int n);
7+
8+
int main() {
9+
10+
int n;
11+
12+
printf("Enter a positive integer: ");
13+
scanf("%d", &n);
14+
15+
printf("The factorial of %d is %d.\n", n, factorial(n));
16+
17+
return 0;
18+
19+
}
20+
21+
int factorial(int n) {
22+
23+
if (n > 0) {
24+
25+
return n * factorial(n-1);
26+
27+
}
28+
else {
29+
30+
return 1;
31+
32+
}
33+
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /