Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int factorial(int number) {
- if(number == 1) {
- return 1;
- }
- return factorial(number - 1) * number;
- }
- int main() {
- cout << factorial(5) << endl;
- return 0;
- }
- // factorial(5) = factorial(4) * 5 = 24 * 5 = 120
- // factorial(4) = factorial(3) * 4 = 6 * 4 = 24
- // factorial(3) = factorial(2) * 3 = 2 * 3 = 6
- // factorial(2) = factorial(1) * 2 = 1 * 2 = 2
- // factorial(1) = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement