Question

In C++ Exercise #3: Write a for loop that will generate and display 10 random numbers...

In C++

Exercise #3: Write a for loop that will generate and display 10 random numbers from 1 to 50. Output all of the randomly generated numbers.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main() {
    srand(time(NULL));  // seeding random number generator
    for(int i = 0; i < 10; ++i) {   // generate 10 random numbers
        cout << 1 + (rand() % 50) << endl;  // print a random number between 1 and 50
    }
    return 0;
}

6984899791 4141324321

Add a comment
Know the answer?
Add Answer to:
In C++ Exercise #3: Write a for loop that will generate and display 10 random numbers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT