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(n1);
}

//Driver function
int main()
{
int n;
printf(“Enter a numbern”);
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



Leave a Reply

Your email address will not be published.