Hi!

Here's my code:

for(i=0;i<N;i++)
  {
   for(j=0;j<M;j++)
 printf("%4.2f ",mat[i][j]);
   printf("\n");
  }

I want it to look like this:
68.85 52.25 32.00
-100.00 -632.25 -26.56

Instead I get:
68.85 52.25 32.00
-100.00 -632.25 -2.56

For life of me I can't remember how to get th alignment right.

Anyone?

Thanks

Hi!

Here's my code:

for(i=0;i<N;i++)
  {
   for(j=0;j<M;j++)
 printf("%4.2f ",mat[i][j]);
   printf("\n");
  }

I want it to look like this:
68.85 52.25 32.00
-100.00 -632.25 -26.56

Instead I get:
68.85 52.25 32.00
-100.00 -632.25 -2.56

For life of me I can't remember how to get th alignment right.

Anyone?

Thanks

The only thing that looks different is the -26.56 and the -2.56

Sorry! it when I wrote it it wa sok I guess when I submitted it, it just moves everythign back.

But I figured it out.

If I want it to be aligned and my maximum charachters is 7
(-100.00) then I need to write

printf("%7.2f",mat[i][j]);

For life of me I can't remember how to get th alignment right.

The alignment includes any precision and formatting characters. Try this.

printf("%7.2f ",mat[i][j]);
This question has already been answered. Start a new discussion instead.