fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int getNumber() {
  6. int n;
  7. do {
  8. cout << "Enter a non-negative number!\n";
  9. cin >> n;
  10. } while (cin && n < 0);
  11. return n;
  12. }
  13.  
  14. int main() {
  15. int n = getNumber();
  16. long double factorial = 1;
  17. for (int i = 1; i <= n; ++i)
  18. factorial *= i;
  19. // cout.precision(2);
  20. cout << n << "! = " << factorial;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3460KB
stdin
13
stdout
Enter a non-negative number!
13! = 6.22702e+09