C program to find factorial of number using function

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(int);
 int n,f;
 printf("Enter the number\n");
 scanf("%d",&n);
 f=fact(n);
 printf("Factorial of %d is %d\n",n,f);
}
int fact(int n)
{
 int fact=1,i;
 for(i=1;i<=n;i++)
 {
  fact=fact*i;
 }
 return(fact);
}

OUTPUT:

Enter the number
5
Factorial of 5 is 120

You may also like...

Leave a Reply

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

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