C Program to find factorial of a number


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


3! = 1 * 2 * 3

4! = 1 * 2 * 3 * 4


Example: How to find factorial of a number in C

Run it Now
#include<stdio.h>

int main() {

   long int n, i, f = 1;

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

   for (i = 1; i <= n; i++) {
       f = f * i;
   }
   printf("\nFactorial is :%ld", f);

   return 0;
}

Output:

Enter a Number :4
Factorial is :24