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