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