Header Ads Widget

Write a program to find the factorial of given number using recursion

 Code:-


#include<stdio.h>

//function for calculating factorial
int fact(int n)
{
if(n==0 || n==1)
return n;
return n*fact(n-1);
}

//Driver function
int main()
{
int n;
printf("Enter a number\n");
scanf("%d",&n);
printf("FActorial of the number is: %d",fact(n));
return 0;
}

Output:-


Enter a number
5
Factorial of the number is: 120