I need to print the prime numbers from 1-1000, except instead of printing the number, i need it to print a 'P'. So, the prime numbers are all p's.
whats wrong with this?
1 2 3 4
while ( array >= 0 )
{
for ( int i = array % 2 == 1 ; array < 1000 ; array++ )
number [array] = 'P' ; // 'P' for Prime
The method is completely wrong. To check if a number, n, is prime, you must check if it divides by any number from 2 up to (n - 1). Your for loop is also not written correctly...
1 2 3 4 5 6
//For loops take this form
//Initialization / Evaluation / Increment
for(i = 1; i < 10; ++i)
{
//Do something
}
So in that for loop there, i is initialized to 1, the for loop checks on beginning every loop if i is less than 10 and if i is not less than 10, breaks out of the loop. It increments i by 1 at the end of each loop.
You would probably want to print something like 'C' in between Ps for composites, otherwise you get just a bunch of PPPPPP without meaning. Do you have now the array with primes flagged already generated with the sieve of eratosthenes and this is totally printing specific or are you still struggling with determining primes like in the thread yesterday?