C++ Write a random number generator function “ rand_integer” that returns a rand
ID: 3838964 • Letter: C
Question
C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output. C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output. C++ Write a random number generator function “ rand_integer” that returns a random integer between -10 and 10. To test this function, declare a function Array named “rand_array with a size of 32, call the rand_integer function to generate 32 random numbers, and store these number in the array. Print out each item in the array as the program output.Explanation / Answer
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <iostream>
using namespace std;
int rand_integer();
int main()
{
srand (time(NULL));
int rand_array[32];
for(int i=0;i<32;i++)
{
rand_array[i]=rand_integer();
}
for(int i=0;i<32;i++)
{
cout<<rand_array[i]<<endl;
}
return 0;
}
int rand_integer()
{
return rand()%(21)-10;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.