c++ program for factorial of a number using recursion

#include<iostream>
using namespace std;
long fact(int num);
int main()
{
int num;
cout<<“Enter number for factorial “;
cin>> num;
cout<<“Factorial of “<< num <<endl<<fact(num);


}
long fact(int num)
{
if(num==0)
return 1;
else
{
return (num*fact(num-1));


}
}

output-
Enter number for factorial 5
factorial of 5
120

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat