C Program using RECURSIVE FUNCTION TO FIND FACTORIAL OF A NUMBER


#include

int fact(int n)
{
int factor=1;
if(n==1)
{
return 1;
}
else
{
factor=n*fact(n-1);
return factor;
}
}

main()
{
int n;
printf(“Enter a number\n”);
scanf(“%d”,&n);
printf(“Factorial of %d = %d\n”,n,fact(n));
}




OUTPUT:



Enter a number

7

Factorial of 7 = 5040

No comments:

Post a Comment