forked from gouravthakur39/beginners-C-program-examples
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFactorial.c
More file actions
26 lines (22 loc) · 651 Bytes
/
Factorial.c
File metadata and controls
26 lines (22 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
int main()
{
int n, i;
unsigned long long factorial = 1;
//unsigned long long is the same as unsigned long long int.
//Its size is platform-dependent, but guaranteed by the C standard (ISO C99) to be at least 64 bits.
printf("Enter a number: ");
scanf("%d",&n);
// Show error if number is less than 0
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else
{
for(i=1; i<=n; ++i)
{
factorial *= i; // factorial = factorial*i;
}
printf("Factorial of %d = %llu", n, factorial);
}
return 0;
}