How to print 5 values per line in C++ using only loop statement and no if-statements? [closed]

I’m guessing what you’re looking for is something similar to this?

#include <iostream>
using namespace std;

int main() 
{
   for(int i = 0; i <= 50; ++i)
   { 
      ((i % 6) == 5) ? cout << i << '\n' : cout << i << ' ';
   }
   return 0;
}

nested for loop example:

#include <iostream>
using namespace std;

int main() 
{
    for(int i = 0; i < 50; ++i)
    { 
        for( int j = 0; j <= 5; ++j)
        {
            cout << (i) << ' ';
            ++i;
        }
        cout << '\n';
    }
    return 0;
}

Browse More Popular Posts

Leave a Comment