1
The program must read a number and compare with the numbers of any 3x3 matrix if the number belongs to a column of the matrix it must print the position, when type 1 it prints two positions, but 1 is only in one position.
#include <stdio.h>
main ()
{
int matriz[3][3];
matriz[1][1] = 1;
matriz[1][2] = 2;
matriz[1][3] = 3;
matriz[2][1] = 4;
matriz[2][2] = 5;
matriz[2][3] = 6;
matriz[3][1] = 7;
matriz[3][2] = 8;
matriz[3][3] = 9;
int coluna, linha, numero;
printf("Digite um numero: ");
scanf("%d", &numero);
fflush(stdin);
for (linha = 1; linha < 4; linha ++){
for (coluna = 1; coluna < 4; coluna ++) {
if(numero == matriz[linha][coluna]){
printf ("\nA posicao do numero eh linha: %d e coluna: %d", linha, coluna);
}
}
}
if (numero < 1 || numero > 9){
printf ("Nao encontrado!");
}
}
And it’s very simple. When you create an array of 3x3 for example, in fact you can only vary from 0 to 2, ie if you create an array [N] , will be accessible from 0 to N-1
– Rodrigo Santiago
Thank you, simple even hahaha ;)
– Karen Santos
@Karensantos Did the answer solve the problem? Do you think you can accept one of them? See the [tour] how to do this. You’d be helping the community by identifying the best solution. You can only accept one of them, but you can vote for anything on the entire site.
– Maniero