Please use c code Write a program that generates a list of 1

(Please use c++ code)
Write a program that generates a list of 100 random integers in [0, 100), which means between 0 and 99 inclusive. To solve this problem, use the randominteger function you developed for the A3 Functions assignment. In other words, use a loop to call the randomlnteger function 100 times. Save the program output by redirecting the standard output stream to a file. To do this, run the program as follows. ./a.out > numbers.txt Open numbers.txt in a text editor to see the result.

Solution

#include <iostream>
#include <stdlib.h> /* we use this header file for srand, rand function */
#include <time.h> /* we use this header file for time */
#include <fstream> //Stream class to write on files

using namespace std;
int randomInteger(); /*randomInteger function declaration for random number generation*/


int main()
{
srand (time(NULL));

/*ofstream data type is used to create files and to write information to files*/
ofstream file(\"numbers.txt\");

/* for loop call randomInteger function 100 times*/
for(int i=0;i<100;i++)
{
/* output storing in file numbers.txt by calling randomInteger function */
file<<\"Random Number \" << i+1 <<\" is : \"<<randomInteger()<<endl;

}

return 0;
}

/*randomInteger function definition */
int randomInteger()
{
/* random number generation between 0 to 99*/
int rand_num=((rand() % 100));
return rand_num;

}

/* after execution this program open number.txt file to see output*/

---------------------------------------------------------

If you have any query, please feel free to ask

Thanks a lot

(Please use c++ code) Write a program that generates a list of 100 random integers in [0, 100), which means between 0 and 99 inclusive. To solve this problem, u

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site