Advertisement
plantbae

Función recursiva

May 4th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <locale.h>
  4. #include <wchar.h>
  5.  
  6.  
  7. using namespace std;
  8. //Función recursiva
  9.  
  10. int factorial(int n)
  11. {
  12.     if (n < 2)
  13.     {
  14.         return 1;
  15.     }
  16.     else
  17.     {
  18.         return n*factorial(n - 1);
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     int num = 0;
  25.     cout << ":: CALCULAR FACTORIAL::\n";
  26.     cout << "Introduzca un número: ";
  27.     cin >> num;
  28.     cout << "\tEl resultado es: " << factorial(num); //Llama a función e imprime el resultado
  29.     system("pause>null");
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement