'Display C Matrix with negative and positive numbers
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!
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mzimmers |
