Está en la página 1de 1

#include "stdafx.

h" #include "iostream" #include "iomanip" using namespace std; void leerValor (int &); long factorial (int); int _tmain(int argc, _TCHAR* argv[]) { int x; char rpta = 'n'; do { system ("cls"); cout<<endl<<setw(40)<<"Factorial de un numero"<<endl; leerValor(x); cout<<endl<<endl<<"\t"<<x<<"! = "<<factorial(x); cout<<endl<<endl<<setw(40)<<"Desea realizar un nuevo calculo(s/n) ?"; cin>>rpta; }while (rpta == 's' || rpta == 'S');

return 0; } void leerValor(int &numero) { do { cout<<"\t Digite un numero (>0): "; cin>>numero; }while(numero<0); } long factorial(int numero) { if (numero==0) return 1; else return numero*factorial(numero-1); }

También podría gustarte