c program to find the factorial using recursion

Programming Example

Write program to compute factorial of a user input number using recursive function.

Solution

#include<stdio.h>
int factorial(int);
int main()
{
	int num,ans;
	printf("Enter any number : ");
	scanf("%d",&num);
	ans=factorial(num);
	printf("Factorial of %d is : %d",num,ans);
	return 0;
}
int factorial(int n)
{
	if(n==1)
		return 1;
	else 
		return n*factorial(n-1);
}
Output

Enter any number : 5

Factorial of 5 is : 120

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad