-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbasic_Factorial.c
More file actions
35 lines (29 loc) · 784 Bytes
/
Copy pathbasic_Factorial.c
File metadata and controls
35 lines (29 loc) · 784 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
27
28
29
30
31
32
33
34
35
/*
* Program: Factorial Calculator
* Author: Pradeep-CodeZ
* Date: 17 Aug 2025
* Description: Calculates the factorial of a given positive integer.
*
* Features:
* - Checks for negative input and handles it gracefully
* - Calculates factorial using a loop
*
* Usage: Compile and run the program
* Example: gcc basic_Factorial.c -o basic_Factorial && ./basic_Factorial
*/
#include <stdio.h>
int main() {
int n, i;
unsigned long long factorial = 1;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n < 0)
printf("Factorial is not defined for negative numbers.\n");
else {
for (i = 1; i <= n; ++i) {
factorial *= i;
}
printf("Factorial of %d = %llu\n", n, factorial);
}
return 0;
}