1. ## Formatting Output

I am trying to format the results of my program into five different columns of an equal number. For example, my program generates 50 random numbers and I am trying to print them out in sets of ten. Here is my code from my main function. Anyone's help would be greatly appreciated

int main(void)
{
float rank[50]={0};
int x, anotherrecord;

do
{
for(x=0;x<50;x++)
{
printf("%3.1f\n", rank[x]);
}

printf("\n Press 1 to generate another random sample: ");
scanf("%d", &anotherrecord);
}
while (anotherrecord == 1);

return 0;
}

2. [code]

for(x=0;x<50;x++)
{
printf("%3.1f\n", rank[x]);
if( x % 10 == 0) printf("\n");

}

Code:
```for(x=0;x<50;x++)
{
printf("%3.1f   ", rank[x]);    /* note spaces  - no \n*/
if(x % 10 == 0) printf("\n");
}```

printf("%3.1f\n", rank[x]);
You can condense this to one line:

printf( "%d - Rank: %3.1f\n", grades[x], rank[x] );

However, what exactly are you trying to do? Do you want more
than one one one line? If so, that \n is your problem. If not, then
what are you trying to do?

Code:
```if( x % 10 == 0 )
{
fgetc( stdin );
}```
Quzah.

5. I now am faced with one more problem. They are formatted in sets of ten, but I need the output to be across the screen not down the screen.

My output currently looks like this

10
10
10

10
10
10

and so on. It should look like

10 10 10 10 10
10 10 10 10 10
10 10 10 10 10

I am going to try and figure out how to do this, but if someone has experience with it and can help me it would be appreciated

6. We've already told you how to fix this. You have to remove that first \n in your printf statement. Second, you have to adjust your printf statements so that the columns line up correctly. Remember that a standard console window is only 80 letters across. This means that you have:

"80 / myprintfstatementlength"

as you maximum number of columns. That being the case, you then have to modify your:

if( x % y == 0 ) printf("\n");

In other words, if your printf is 20 characters in length, then at a maximum, you only get 4. So, replace y with 4.

Quzah.

7. If what u want is to format across columns something like this:

col1 col2 col3 col4 col5
1 11 21 31 41
2 12 22 32 42
.. .. .. .. ..

then something like the below pgm cud work. check it out

--------------------------------------------------
#include <stdio.h>

int main()
{
int x[50], i = 0, j = 0;

for(i = 0; i <= 49; i++)
{
x[i] = i; /*initialize the array */
}

for(i = 0; i < 10; i++)
{
for(j = 0; j < 5; j++) /* print in 5 columns */
{
printf("element = (%d) \t" , x[i + j*10]);
}
printf("\n"); /* go to the next row */
}

return 0;
}

--------------------------------------------------