Print factorial of a number - C Program

C program to read a number and find factorial.

Solution:

#include<stdio.h>
int main()
{
      int n, i;
      /*To store large value of fact variable defined it as long int. The range of int is smaller than long int.*/
      long int fact=1;
      printf("Enter Number : ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            fact=fact*i;
      }
      printf("\nFactorial of %d : %ld",n,fact);
      return 0;
}


Output:

factorial of number