FCTRL2 Problem

  1. #include

  2. int factorial(int number) {

  3. int result = 1;
    
  4. for(int i = number; i > 0; i--) {
    
  5.     result = result * i;
    
  6. }
    
  7. return result;
    
  8. }

  9. int main() {

  10. int t;
    
  11. std::cin >> t;
    
  12. while (t--) {
    
  13.     int n;
    
  14.     std::cin >> n;
    
  15.     std::cout << factorial(n) << '\n';
    
  16. }
    
  17. return 0;
    
  18. }
    Please Tell, What is wrong in this code. Why is it wrong?

The range for factorials is between 1 to 100, so after a certain number the factorial exceeds the range which int or long long int can store, So when you will calculate the factorial of big number it will cause overflow and you will get WA.