### Prime numbers: print 10 only per line

Hey guys, I'm fairly new to C++ and programming, one of my task is to print the first 100 prime numbers, with 10 of them per line with size 4. I got on really well with the finding of the prime numbers but how do you print 10 per line and change the size? Many thanks, here's what I got so far:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include #include #include #include using namespace std; int IsPrimeNumber(int i); int main() { int i; int primesFound; i = 1; primesFound = 0; cout << "The first 100 prime numbers are:" <
Last edited on
Between 23 and 27 line:
 ``1234567`` `````` if(IsPrimeNumber(i) == 1) { cout << i << " "; primesFound++; if (primesFound % 10 == 0) cout << endl; }``````
About size: you cannot change size of your text in terminal window. But you could use OS specific API to change font size of the terminal. NOTE: it will change size of ALL text. You cannot have two words of different font size on single terminal window simultaneously.
Also I slightly optimized your code:
 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include #include bool isPrimeNumber(int i) { for(int j = 2; j <= (i/2); ++j) { if((i%j) == 0) return false; } return true; } int main() { using namespace std; int i = 2; //1 isn't a prime number int primesFound = 0; cout << "The first 100 prime numbers are:" << endl; while(primesFound < 100) { if(isPrimeNumber(i)) { cout << setw(4) << i; ++primesFound; if (primesFound % 10 == 0) cout << endl; } ++i; } return 0; }``````
guys thanks so much, really helpful. Cheers!
Topic archived. No new replies allowed.