# Thread: making rows in terms of columns?

1. ## making rows in terms of columns?

Here is my code below. If I enter 2 for "How many rows question" and 9 for "How many values to be used question... I get the following result...

Code:
```1     3      5     7     9
2     4      6     8```
Now, the code does what I want but I'm asking how many rows the user wants.

I want the user to be able to enter in how many columns he wants instead of how many rows rows (but I want the same result as before) how would I go about doing it?

Code:
```#include <stdio.h>

int func_col(int, int);

int main()
{
int q, a, b, c, x, row, max_value;

printf("How many rows? ");
scanf(" %d", &row);

printf("How many values to be used? ");
scanf(" %d", & max_value);

q = func_col(max_value, row);

for(b=1, c=0; c<row; c++)
{
x=b;
for(a=0; a<q+1; a++)
{
if(x<max_value+1)
printf("%d\t", x);

x+=row;
}
b++;
printf("\n");
}
}

int func_col(int max_value, int row)
{
if(row<5)
return(max_value / row);
else
return((max_value / row)+1);
}```

2. Something like below?
I rewrote it and used other names for the variables.

Code:
```#include <stdio.h>

int calcRows( int cols, int maxVal );

int main( )
{
int columns, rows, maxValue, startValue=1, incrementValue;

printf( "How many columns? " );
scanf( " %d", &columns );

printf( "How many values to be used? " );
scanf( " %d", & maxValue );

rows = calcRows( columns, maxValue );

for( int i=0; i<rows; i++ )
{
incrementValue = startValue;

for(int j=0; j<=columns; j++)
{
if( incrementValue <= maxValue )
printf( "%d\t", incrementValue );

incrementValue += rows;
}
startValue++;
printf( "\n" );
}

return 0;
}

int calcRows( int cols, int maxVal ){
if( maxVal%cols == 0 )
return 	maxVal/cols;
else
return 	maxVal/cols + 1;
}```

3. sorry for late reply, but thanks! it works the way iwanted.