C Program to find factorial of a number using function


In this program, You will learn how to find factorial of a number using function in c.


3! = 1 * 2 * 3

4! = 1 * 2 * 3 * 4


Example: How to find factorial of a number using function in c

Run it Now
#include<stdio.h>

int fact(int n) {
   int f = 1, i;
   for (i = 1; i <= n; i++) {
       f = f * i;
   }
   return f;
}

int main() {

   int n, fa;

   printf("Enter a Number :");
   scanf("%d", &n);

   fa = fact(n);
   printf("\nThe Factorial is :%d", fa);

   return 0;
}

Output:

Enter a Number :4
The Factorial is :24