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.

#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("Factorial is:%ld", f);

  return 0;
}

Output:

Enter a number:4                                                                                                                      
Factorial is:24