Numbers 11 through 23 in 5 columns:
11 14 17 20 22
12 15 18 21 23
13 16 19
>You don't need an array.
If the problem is printing the numbers in linear order as specified then an array is the easiest (and most general) method by far. If the items are a nice sequence of numbers as shown in the example then a beginner could probably figure it out in an afternoon:
Code:
#include <iostream>
using namespace std;
int main()
{
int start, end, cols;
cout<<"Starting value, ending value and columns: ";
cin>> start >> end >> cols;
const int count = end - start + 1;
const int rows = ( ( count / cols ) + count ) / cols;
cout.put ( '\n' );
for ( int i = 0, first = start; i < rows; i++, first++ ) {
for ( int j = first; j <= end; j += rows )
cout<< j <<' ';
cout.put ( '\n' );
}
}
But the array based solution is immediately obvious.
>Where is a good place for me to start?
Instead of using a loop like this for filling the array:
Code:
for ( int i = 0; i < rows; i++ ) {
for ( int j = 0; j < cols; j++ )
a[i][j] = val;
}
Use something more like this:
Code:
for ( int i = 0; i < cols; i++ ) {
for ( int j = 0; j < rows; j++ )
a[j][i] = val;
}