Can you help me ???

This code is show all the composite numbers1 to 100. how can i add a limit of 5 column in this sample program??

SAMPLE OUTPUT!

 4   6   8   9  10
12  14  15  16  18
...so on..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<iomanip>
#include<conio.h>

using namespace std;

int main(){
     int i,j;

for(i=2;i<=100;i++) 
 {
  for( j=2;j<=i/2;j++)
   {
     if(i%j==0)
     {
      cout<<setw(5)<<i;
      break;
     }
  }
 }
getch();
}

Just use a counter in there.

 
if( (count++ % 5) == 0 ) cout << endl;
Last edited on
Topic archived. No new replies allowed.