Table of Contents
show
Finding Factorial using Recursion
#include<stdio.h>
int factorial(int x);
int main()
{
int n,fact;
printf("Enter number");
scanf("%d",&n);
fact = factorial(n);
printf("Factorial of %d is %d\n",n,fact);
return 0;
}
int factorial(int x)
{
if(x == 0)
{
return 1;
}
else
{
return x*factorial(x-1);
}
}
Output
Enter number 5
Factorial of 5 is 120
Views: 1