12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
#include "pch.h" #include <iostream> #include <fstream> using namespace std; int main() { ofstream file; file.open("randomData.txt"); srand((unsigned)(0)); int ran_data; for (int index = 0; index < 100; index++) { ran_data = (rand() % 101) + 100; } file << ran_data; file.close(); int array[101] = {}; ifstream is("ran_data"); int num = 0; int x; while (num < array[101] && is >> x) array[num++] = x; cout << "The random numbers are:" << "\n"; for (int i = 0; i < num; i++) { cout << array[i] << ' '; } is.close(); return 0; }
while (num < 101..;
#include <iostream> #include <fstream> using namespace std; int main() { ofstream file; file.open("randomData.txt"); srand((unsigned)(0)); int ran_data; for (int index = 0; index < 100; index++) { ran_data = (rand() % 101) + 100; file << ran_data << endl; } file.close(); int array[101] = {}; ifstream is("randomData.txt"); int num = 0; while (num < 100) { is >> array[num++]; } cout << "The random numbers are:" << "\n"; for (int i = 0; i < num; i++) { cout << array[i] << ' '; } is.close(); return 0; }