Advertisement
ranisalt

Fatorial recursivo

Feb 13th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int fatorial(int a)
  7. {
  8.     if (a <= 1)
  9.     {
  10.         return 1;
  11.     }
  12.     return a * fatorial(a - 1);
  13. }
  14.  
  15. int main()
  16. {
  17.     int a;
  18.         cout << "Informe o nΓΊmero:" << endl;
  19.     cin >> a;
  20.     cout << fatorial(a) << endl;
  21.     system("pause");
  22.         return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement