Prime numbers over 1000
Apr 10, 2013 at 11:15pm UTC
I tried making an array of 30...but nothing is coming out. Tried a combination of a while/for loop...but I think I'm confusing the program. Can I get some assistance, please?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int N[30], *pN;
pN = N;
PrimeArray(pN,30);
PrimeArrayDisplay(pN, 30);
return 0;
}
void PrimeArray(int *PrArray, int Number)
{
int i, k, prime;
i = 0;
while (1 < Number)
{
prime=2;
int limit = sqrt(double (prime));
for (k = 2; k <= limit; k++)
{
if (limit % k == 0)
{
break ;
}
}
if ( k == limit)
{
*PrArray++ = prime;
i++;
}
prime++;
}
}
void PrimeArrayDisplay(int *PrArray, int Number)
{
cout << "Display 30 Prime Numbers > 1001" ;
int i;
i = 0;
while (k < Number)
{
cout << "\n\t\t\tThe array N[" << setw(2) << i << "] = " << *PrArray++;
i++;
}
}
Apr 10, 2013 at 11:34pm UTC
Apr 11, 2013 at 3:40am UTC
ok...I'm new so I haven't searched far. Thanks Zaita.
Topic archived. No new replies allowed.