Prime Number Generator... Help !?!!
So we have an assigment in class to make a program that produces 100 random numbers prints the randoms to a txt then outputs the prime numbers. I am almost sure this code is working ut I am at my GF house and she has some getto C++ compiler can someone run this for me and see if I error. And if I do what is wrong ????
Thanks in advance !
Code:
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<time.h>
#include<fstream.h>
#include<math.h>
int main()
{
int numx;
int i, max, p;
char stop;
ofstream outputfile ("randnums.txt");
srand(time(0)); //this will produce a new number after each execution.
int array[100];
for(int z = 0;z < 100; z++) // Produces 100 random numbers
{
numx = 1+rand()%250; // Numbers range from 1-250
array[z]=numx;
outputfile << numx << endl; //inputs numbers into array
}
outputfile.close();
for(i = 0; i < 100; i++)
{
max = sqrt(array[i]);
bool prime = true;
for(p = 2; (p <= max) && prime; p++)
{
if((p % array[i]) == 0)
prime = false;
}
cout << array[i] << " ";
}
cin >> stop;
return 0;
}