Friday, October 30, 2009

Finding Factorial

Write a function to calculate the factorial value of any integer entered through the keyboard.

void main()
{
float fact(float);
float a,a1;
printf("\nInput a number to find the factorial");
scanf("%f",&a);
a1=fact(a);
printf("\nThe factorial of %f is %f",a,a1);
}

float fact(float x)
{
float f;

if(x==1)
return(1);

else
f=x*fact(x-1);

return(f);
}

No comments:

Post a Comment