Factorial of a given numbers in unix using c?

1 answer

Answer

1042231

2026-07-27 11:55

+ Follow

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.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.