Thursday 1 February 2018

Example Recursive Function in C Language

Write a program to calculate the factorialof a positiv intger using recursive function.

long int fact(n)
int n;
{
long int result;
if(n==0)
result=1;
else
result=n*fact(n-1);
return (result);
}
voidmain( )
{
int I;
for(i=0;i<10;i++)
{
printf(“%d\n”,i,fact(i));
}
}



Output:

0!=1
1!=1
2!=2
3!=6
4!=24
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800

Share this

0 Comment to "Example Recursive Function in C Language"

Post a Comment