Write a program to find the Factorial of a number using Recursion :-


//Factorial of a number using Recursion

#include<stdio.h>
#include<conio.h>
		
int fact(int no);
main()

{
int no,ans;
printf("Enter any number:");
scanf("%d",&no);

ans=fact(no);
printf("Factorial of a number is:%d",ans);
getch();
}

int fact(int x)
{
int f;
if(x==0)
{
return 1;
}
else
{
f=x*fact(x-1);
return f;
}
}

Output:


Enter any number:12
Factorial of a number is:479001600

			

Previous Next


NOTE:- The factorial of a negative number doesn't exist. And the factorial of 0 is 1.