Advertisement
soyan_bid

faktorial_rekursi

Apr 18th, 2016
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int faktorial(int n);
  5.  
  6. main()
  7. {
  8.     int input;
  9.     cout << "Input n : ";
  10.     cin >> input;
  11.     cout << "Result : ";
  12.     cout << faktorial(input);
  13. }
  14.  
  15. int faktorial(int n)
  16. {
  17.     if(n == 0 || n == 1)
  18.         return 1;
  19.     else
  20.         return n * faktorial(n-1);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement