Advertisement
JosepRivaille

P57474: Factorial iteratiu

Mar 14th, 2015
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int factorial(int n) {
  6.     int f = 1;
  7.     for (int i = 1; i <= n; ++i) {
  8.         f = f*i;
  9.     }
  10.     return f;
  11. }
  12.  
  13. //Pre: Llegeix un natural
  14. //Post: Calcula el factorial
  15. int main() {
  16.     int n;
  17.     cin >> n;
  18.     cout << factorial(n) << endl;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement