-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab2-1.c
More file actions
32 lines (23 loc) · 683 Bytes
/
lab2-1.c
File metadata and controls
32 lines (23 loc) · 683 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
#include <stdio.h>
/* Function declaration for non-recursive factorial */
int factorial_non_recursive(int n);
int main() {
int number;
int result;
/* Get the number from the user */
printf("Enter a positive integer: ");
scanf("%d", &number);
/* Calculate the factorial using non-recursive function */
result = factorial_non_recursive(number);
/* Output the result */
printf("Factorial of %d is: %d (Non-Recursive)\n", number, result);
return 0;
}
/* Non-recursive factorial function */
int factorial_non_recursive(int n) {
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}