The following code can be used to complete the given problem in C++.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num, min, max;
ofstream myfile;
myfile.open ("example.txt");
cout<<"Enter number of elements to be generated : ";
cin>>num;
cout<<"Enter the values : ";
cin>>min>>max;
while(num--)
{
int randNum = rand()%(max-min + 1) + min;
myfile<<randNum;
myfile<<"\n";
}
myfile.close();
return 0;
}
Please upvote the answer if you find it helpful.
Get Answers For Free
Most questions answered within 1 hours.