fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int MAXVAL = 11, COLS=3, display, nearest3;
  6. if (MAXVAL % 3 > 0)
  7. nearest3 = MAXVAL + (3 - MAXVAL % 3);
  8. else
  9. nearest3 = MAXVAL;
  10.  
  11. cout << "nearest3 is " << nearest3 << endl;
  12. int ROWS = nearest3/COLS;
  13. cout << "ROWS is " << ROWS << endl;
  14.  
  15. for(int r=1; r<=ROWS; r++) {
  16. if(r+(nearest3/COLS)*2 <= MAXVAL)
  17. cout << r << " " << r+(nearest3/COLS) << " " << r+(nearest3/COLS)*2 << endl ;
  18. else if(r+(nearest3/COLS) <= MAXVAL)
  19. cout << r << " " << r+(nearest3/COLS) << " " << endl ;
  20. else
  21. cout << r << " " << endl ;
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
nearest3 is 12
ROWS is 4
1 5 9
2 6 10
3 7 11
4 8