C programming windows console application visual studio Writ
C++ programming windows console application visual studio
Write a program that generates fifty (50) random numbers between 1 and 50 and stores the numbers in a text file named numbers.txt.//numone.cpp//Author://Date://#include #include #include using namespace std; int main() {//declare variables return 0;}//End of main functionSolution
RandNum.cpp
#include <iostream>
 #include <cstdlib>   
 #include <ctime>   
 #include <fstream>
 using namespace std;
int main () {
 ofstream outputFile;
 outputFile.open (\"numbers.txt\");
 srand (time(NULL));
/* generate secret number between 1 and 50: */
 for(int i=0; i<50; i++){
 outputFile << (rand() % 50 + 1)<<endl;
 }
 cout<<\"File has been created\"<<endl;
 outputFile.close();
 return 0;
 }
Output:
sh-4.3$ g++ -std=c++11 -o main *.cpp sh-4.3$ main File has been created
numbers.txt
48
 21
 19
 34
 15
 7
 46
 10
 8
 4
 8
 50
 27
 49
 46
 14
 12
 14
 12
 15
 29
 8
 23
 29
 31
 46
 2
 2
 8
 37
 22
 8
 8
 40
 41
 24
 46
 38
 35
 5
 41
 43
 4
 17
 43
 1
 33
 4
 14
 46


