11 – Best C program to find factorial using recursion

C program to find factorial using recursion

Factorial is multiplying number by every number below it till 1.

Recursion : “The repeated application of a recursive procedure or definition.” – Oxford Languages
In programming we have recursion functions, these functions are the functions which call themselves in the same function.
In simple words if any function calls itself then it is known as recursion.

C program to find factorial of a number using recursion​

#include <stdio.h>
//itvoyagers.in
int fact(int x)
{
if(x != 0)
{
return x * fact(x-1);
}
else
{
return 1;
}
}
//itvoyagers.in
int main()
{
int num,rsl;
printf("Enter enter any number : ");
scanf("%d",&num);
rsl = fact(5);
printf("Factorial of %d is %d", num, rsl);
return 0;
//itvoyagers.in
}

Output :

Enter enter any number : 5
Factorial of 5 is 120

Connect with us on following platforms

We are aiming to explain all concepts of C in easiest terms as possible. ITVoyagers
Author