Advertisement
soyan_bid

faktorial_iterasi_2

Apr 18th, 2016
352
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 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.     int hasil = 1;
  18.     for(int i = n; i > 0; i--)
  19.     {
  20.         hasil = hasil * (i);
  21.     }
  22.     return hasil;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement