To calculate the factorial of a given number in C on a Unix system, you can use a simple recursive or iterative function. Here's an example of an iterative approach:
<code class="language-c">#include <stdio.h>unsigned long long factorial(int n) { unsigned long long result = 1; for (int i = 1; i <= n; i++) { result *= i; } return result; }
int main() { int number; printf("Enter a positive integer: "); scanf("%d", &number); printf("Factorial of %d is %llu\n", number, factorial(number)); return 0; }
</code>
Compile the code using gcc filename.c -o factorial and run it with ./factorial to calculate the factorial of a number.
Copyright © 2026 eLLeNow.com All Rights Reserved.