-1
Good afternoon Guys!!!!
I know the question seems silly, but I’m starting now in programming needed to do a C program with a MATRIX[4][4] as described here below. I’ve been trying for a few days, but without success.
The user will not enter any data is only to show the same described data below neither more nor less.
Create a C PROGRAM that displays the following output:
Row: 0 column: 1 value: 1
Row: 1 column: 1 value: 2
Row: 2 column: 1 value: 3
Row: 3 column: 1 value: 4
Row: 4 column: 1 value: 5
This is the code I made.
The Program runs error-free, but does not print the values of the above example, prints the wrong numbers, does not show the values of the row or column.
Thanks in advance. :).
#include <stdio.h>
#include <stdlib.h>
int main()
{
int l, c, cont, matriz[4][4];
char valor = 'x';
cont = 0;
for (l = 0; l < 4; l++)
{
for (c = 0; c < 2; c++)
{
matriz[l][c] = cont + 1;
}
}
for (l = 0; l < 4; l++)
{
for (c = 0; c < 2; c++)
{
printf("Linha: %d Coluna: %d Valor: %s", matriz[l][c], valor);
}
printf("\n");
}
return (0);
}`
If I understand correctly your problem change:
printf("Linha: %d Coluna: %d Valor: %s", matriz[l][c], valor);
for:printf("Linha: %d Coluna: %d Valor: %d", l, c, matriz[l][c]);
.– anonimo
Why create the 4x4 matrix if you only use up the second column? Besides, it does not make sense that you print the letter "x" several times, I think that x should be exchanged for the respective value of that row and column, no? (As suggested by the comment above) - If I were to print the letter "x" several times, I wouldn’t even need this matrix, I would just loop it
– hkotsubo
Thanks for the help, my printf was wrong. Thinking here you are right to display several times the X.
– Pedro Salles
I reversed the issue because it changed the question, and that’s bad because it invalidates the answers that have already been given. If you want to ask something else (even if it is related), then ask another question
– hkotsubo
I got it,I registered today and it was my first question here. More beauty, I’ll pay attention to it next time. VLW.
– Pedro Salles