Write a program to find the factorial of the given number using function with while loop.
/* Write a program to find the factorial of the given number using function with while 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)
{
long fact=1;
while(x>1)
{
fact*=x--;
}
return fact;
}
Comments
Post a Comment