Write a program to find the factorial of the given number using function with for loop.
/* Write a program to find the factorial of the given number using function with for loop*/
#include
<stdio.h>
long
factorial(int);
void main()
{
int n,f;
printf("Enter the number : ");
scanf("%d",&n);
f=factorial(n);
printf("Factorial = %ld\n",f);
getch();
}
long
factorial(int x)
{
int i;
long fact=1;
for(i=1;i<=x;i++)
{
fact*=i;
}
return fact;
}
Comments
Post a Comment