Use of Recursive function in C

Recursive Function:- A function call itself

Code

int fac(int num);
void main()
{
int a;
clrscr();
printf(“Enter any Number:->>”);
scanf(“%d”,&a);
printf(“Factorial of %d is %d”,a,fac(a));
getch();
}
int fac(int num)
{
if(num==1)
return num;
num = num*fac(num-1);
}

Note- Kindly save the above program with extension .c before running.

Output

Leave a Reply