fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. int factorial = 1.0;
  7. cout << "Input number: ";
  8. cin >> n;
  9. if (n < 0)
  10. cout << "Error! Invalid input";
  11. else {
  12. for(int i = 1; i <= n; ++i) {
  13. factorial *= i;
  14. }
  15. cout << "Factorial of " << n << " = " << factorial;
  16. }
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5432KB
stdin
5
stdout
Input number: Factorial of 5 = 120