Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prints a random integer. The C++ standard library contains

ID: 3824235 • Letter: W

Question

Write a program that prints a random integer. The C++ standard library contains a pseudo random number generator that you can use to solve this problem. The function rand returns a pseudo random number. To use rand in your programs, you need to include the cstdlib header as follows. #include The function rand will return the same sequence of values for a given seed. You can change the sequence of values it returns by changing the seed as follows. srand(719);//Seed the random number generator with 719. The following is an example of how you can use the return value of rand. cout

Explanation / Answer


#include <iostream>
#include<cstdlib>

int main()
{
srand(time(0));// This will generate a new randomized number by help of time.
int num = rand(); // storing the random integer in the variable num
  
std::cout << num;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote