Printing prime numbers

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 
try initialising the array then write:

[for(i = 0;i < 1000; i++)
{
if((number[i]) % 2 == 1) cout <<"P";
else cout <<number[i];
}
]
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.

Last edited on
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?
Topic archived. No new replies allowed.