Advertisement
Josif_tepe

Untitled

Oct 10th, 2023
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int faktoriel(int n) {
  5.     if(n <= 1) {
  6.         return 1;
  7.     }
  8.    
  9.     return faktoriel(n - 1) * n;
  10. }
  11. int main() {
  12.     cout << faktoriel(3) << endl;
  13.     return 0;
  14. }
  15.  
  16. // faktoriel(3) = faktoriel(2) * 3 = 2 * 3 = 6
  17. // faktoriel(2) = faktoriel(1) * 2 = 1 * 2 = 2
  18. // faktoriel(1) = 1
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement