Skip to content

Commit

Permalink
Add recursive factorial calculation
Browse files Browse the repository at this point in the history
Andy9822 committed Oct 20, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c723edd commit 17ecc56
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions CPP/factorial_recursive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int recursive_factorial(int number)
{
if (number == 0 || number == 1)
{
return 1;
}

return number * recursive_factorial(number - 1);
}

int main()
{
int number;
cout<<"Include a number to have it's factorial calculated (must be greater or equal to 0)"<< endl;
cin >> number;

int factorial = recursive_factorial(number);

cout << "Factorial of " << number << " is: " << factorial << endl;

return 0;
}

0 comments on commit 17ecc56

Please sign in to comment.