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 *

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat