Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 6.16
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- int main()
- {
- srand(static_cast<unsigned int>(time(0)));
- // a.) 0 ≤ n ≤ 3
- for(int i = 0; i < 10; i++) cout << "0 <= n <= 3: " << rand() % 4 << endl;
- cout << endl;
- // b.) 1 ≤ n ≤ 50
- for (int i = 0; i < 10; i++) cout << "1 <= n <= 50: " << 1 + rand() % 50 << endl;
- cout << endl;
- // c.) 2 ≤ n ≤ 44
- for (int i = 0; i < 10; i++) cout << "2 <= n <= 44: " << 2 + rand() % 43 << endl;
- cout << endl;
- // d.) 500 ≤ n ≤ 678
- for (int i = 0; i < 10; i++) cout << "500 <= n <= 678: " << 500 + rand() % 179 << endl;
- cout << endl;
- // e.) –2 ≤ n ≤ 2
- for (int i = 0; i < 10; i++) cout << "-2 <= n <= 2: " << -2 + rand() % 5 << endl;
- cout << endl;
- // f.) –3 ≤ n ≤ 12
- for (int i = 0; i < 10; i++) cout << "-3 <= n <= 12: " << -3 + rand() % 16 << endl;
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment