Question. Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline. Ex:
101
133
Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, srand() has already been called; do not call srand() again.
Complete Solution:-
C++ program
#include <iostream>
#include <cstdlib> // library in which rand() defined
using namespace std;
int main()
{
int start = 100, end = 149,limit;
limit=(end - start + 1);
cout<<"First random num: "<<100 + rand() % limit <<endl; // statement 1
cout<<"Second Random num: "<<100 + rand() % limit <<endl; // statement 2
return 0;
}
Our Happy Testimonials
They are fast in responding to homework questions. they have the best technical writers. Thanks for helping me with my programming doubts.
I contact to disklib for homework, they help me out, despite there was some technical issue they gone through extra mile for me and provide me good quality work in first priority. 100% recommended.
Desklib's study resources are best & unique. Their study database is easy to access and easy to use.
100 % recommended.