0

I was given a problem that needs to transform a matrix using a specific rule and then print it.

I have a 10x20 double matrix that I need to display in the command prompt using C. However, when it has negative numbers it becomes unorganized. My printing function is this:

int print(const double f[N][M])
{
    int i,j;

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

Thanks in advance for your help!enter image description here

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

1 Answers1

0

I'm assuming that by "disorganized" you mean that your columns aren't properly aligned. (I can't see anything else wrong with it.) Look at this thread:

TL;DR:

printf("% 6.1f\n", f[i][j]);

Substitute your desired value for the "6" in that statement.

mzimmers
  • 857
  • 7
  • 17