Friday, February 3, 2017

            C PROGRAM TO  CALCULATE  FACTORIAL OF A NUMBER USING RECURSION              

WAP in c  to calculate the factorial of a number. Use the concept of recursion 
instead of using loops.


#include<stdio.h>
main()
{
int afact;
printf("\nEnter any number: ");
scanf ("%d"&a);
fact=rec (a);
printf("\nFactorial Value = %d"fact);
getch();
}
rec (int x)
{
int f;
if (x==1)
return (1);
else
f=x*rec(x-1);
return (f);                                           OUTPUT OF THE PROGRAM
}

No comments:

Post a Comment