Last active
February 4, 2018 16:59
-
-
Save hckim16/f5d33e442783d61db6ef1943d4783073 to your computer and use it in GitHub Desktop.
Simple recursive code for factorial solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int factorial(int n){ | |
if(n == 0){ | |
return 1; | |
} | |
else{ | |
return n * factorial(n-1); | |
} | |
} | |
int main(){ | |
int n; | |
cout << "Enter number: "; | |
cin >> n; | |
cout << "The answer is: " << factorial(n) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment