fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cout << "enter a non-negative integer: ";
  7. cin >> n;
  8.  
  9. while (n < 0) {
  10. cout << "invalid input! enter a non-negative integer: ";
  11. cin >> n;
  12. }
  13.  
  14. unsigned long long factorial = 1;
  15.  
  16. for (int i = 1; i <= n; i++) {
  17. factorial *= i;
  18. }
  19.  
  20. cout << n << "! = " << factorial << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
enter a non-negative integer: 21930! = 0