Tuesday, November 22, 2016

Factorial of a number using Recursion

Hopefully this code will help you to understand Recursion well.



#include<stdio.h>
#include<conio.h>

long int factorial(long int x)
{
if(x<=0)
return 1;
else
return x*factorial(x-1);
}
void main()
{
long int n,y;
clrscr();
scanf("%ld",&n);
y=factorial(n);
printf("the factorial is:%ld",y);
getch();
}

No comments:

Post a Comment