Find factorial of a number using recursion in c++

Avinash
1 min readJul 24, 2020
A laptop for programming
Photo by Maxwell Nelson on Unsplash

#include <iostream>
using namespace std;

int fact(int number){
if(number == 1){
return 1;
}
else{
return number*fact(number-1);
}
}

int main() {
int n;
cout<<”Enter number to find factorial”<<endl;
cin>>n;
int factorial = fact(n);
cout<<”factorial of number “<<n<<” is “<<factorial<<endl;
return 0;
}

Conclusion: We have seen how to find factorial of a number using recursion in c++ language.

--

--

Avinash

I am a passionate programmer and full stack developer. I love to study about data structures and algorithms. Here generally write about javascript , ReactJs..