Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 43: Write a C++ program to print factorial of a number by using recursion.

#include<iostream>
using namespace std;

int fact(int n)
{
	if(n==1||n==0)
	return n;
	else
	return n*fact(n-1);
}

int main()
{
	int num;
	cout<<"\nenter a number : ";
	cin>>num;
	cout<<"\nfactorial of a given number : "<<fact(num);
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.