Skip to content

Commit 5967aa5

Browse files
Create Factorial.c
C Program to find the factorial of a number
1 parent d2e7e2a commit 5967aa5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Factorial.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
include <stdio.h>
2+
int main()
3+
{
4+
int n, i;
5+
unsigned long long factorial = 1;
6+
7+
printf("Enter a number: ");
8+
scanf("%d",&n);
9+
10+
// SHow error if number is less than 100
11+
if (n < 0)
12+
printf("Error! Factorial of a negative number doesn't exist.");
13+
14+
else
15+
{
16+
for(i=1; i<=n; ++i)
17+
{
18+
factorial *= i; // factorial = factorial*i;
19+
}
20+
printf("Factorial of %d = %llu", n, factorial);
21+
}
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)