garryhtreez

5.13

Nov 13th, 2020 (edited)
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. /* 5.13 Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  2.    Visual Studio Community 2019 */
  3.  
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <limits>
  7. using namespace std;
  8.  
  9. int main(void) {
  10.  
  11.     long long factorial{ 1 };
  12.  
  13.     cout << "\n" << setw(5) << "n" << setw(22) << "n!";
  14.  
  15.     for (int n{ 1 }; n <= 20; n++) {
  16.         factorial *= n;
  17.         cout << "\n" << setw(5) << n << setw(22) << factorial;
  18.         if (factorial > 2147483647) cout << " (long int breaks at " << LONG_MAX << " + 1)";
  19.     }
  20.     cout << "\n\n";
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment