fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cout << "Ingrese un número entero no negativo (n): ";
  7. cin >> n;
  8.  
  9. // Validar la entrada
  10. if (n < 0) {
  11. cout << "Error: El número debe ser no negativo." << endl;
  12. return 1; // Salir del programa con código de error
  13. }
  14.  
  15. // Calcular el factorial
  16. unsigned long long factorial = 1; // Inicializar el factorial en 1
  17. for (int i = 1; i <= n; i++) {
  18. factorial *= i; // Multiplicar factorial por i
  19. }
  20.  
  21. // Mostrar el resultado
  22. cout << n << "! = " << factorial << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Ingrese un número entero no negativo (n): 22081! = 0