garryhtreez

6.16

Dec 8th, 2020
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /* 6.16
  2.    Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  3.    Visual Studio Community 2019
  4. */
  5.  
  6. #include <iostream>
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include <iomanip>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.    srand(static_cast<unsigned int>(time(0)));
  15.  
  16.       // a.)  0 ≤ n ≤ 3
  17.       for(int i = 0; i < 10; i++) cout << "0 <= n <= 3: " << rand() % 4 << endl;
  18.       cout << endl;
  19.  
  20.       // b.) 1 ≤ n ≤ 50
  21.       for (int i = 0; i < 10; i++) cout << "1 <= n <= 50: " << 1 + rand() % 50 << endl;
  22.       cout << endl;
  23.  
  24.       // c.) 2 ≤ n ≤ 44
  25.       for (int i = 0; i < 10; i++) cout << "2 <= n <= 44: " << 2 + rand() % 43 << endl;
  26.       cout << endl;
  27.  
  28.       // d.) 500 ≤ n ≤ 678
  29.       for (int i = 0; i < 10; i++) cout << "500 <= n <= 678: " << 500 + rand() % 179 << endl;
  30.       cout << endl;
  31.  
  32.       // e.)  –2 ≤ n ≤ 2
  33.       for (int i = 0; i < 10; i++) cout << "-2 <= n <= 2: " << -2 + rand() % 5 << endl;
  34.       cout << endl;
  35.  
  36.       // f.)  –3 ≤ n ≤ 12
  37.       for (int i = 0; i < 10; i++) cout << "-3 <= n <= 12: " << -3 + rand() % 16 << endl;
  38.       cout << endl;
  39.  
  40.    return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment