C program to find factorial of a number

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
main()
{
 int fact=1,i,n;

//Accepting number
 printf("Enter the number \n");
 scanf("%d",&n);

//Finding factorial
 for(i=1;i<=n;i++)
 {
  fact=fact*i;
 }

//Printing factorial
 printf("Factorial of %d is %d",n,fact);
}

OUTPUT:

Enter the number
5
Factorial of 5 is 120

Leave a Reply

Your email address will not be published. Required fields are marked *

fifteen − 10 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.