Matrix, Float, matrix position

Asked

Viewed 28 times

-2

Could someone show my error? I had to leave a 3x3 matrix, I just need the output to be like this:

0 0 0
0 0 0
0 0 0
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define linha 3
#define coluna 3

int main()
{
    int l, c, i, j;
    float mesas[linha][coluna];


    for(l = 0;l < linha; l++){
        printf("\nLinha %i\n", l+1);
        for(c = 0; c < coluna; c++){
            printf("coluna %i: ", c+1);
            scanf("%f", &mesas[l][c]);
        }
    }

    printf("\nMatriz gerada\n");

    for(i = 0; i < linha; i++)
    {
        for(j = 0;j < coluna; j++)
        {
            printf("%d\t", mesas[l][c]);
        }
    }
    return 0;
}
  • ta have any compilation error? execution? what’s your problem??

1 answer

1

Just put a printf skipping a line at the end of the loop of I , so that always end the line jump line

for(i = 0; i < linha; i++)
{
    for(j = 0;j < coluna; j++)
    {
        printf("%.1f\t", mesas[l][c]);
    }
    printf("\n");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.