Thursday, 23 February 2012

hi
#include
#include
#include
#include
#include
#include


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;
}

No comments:

Post a Comment