1
Good afternoon friends, I am trying to make an exchange in an array, exchange the values of the first row with the values of the last column. I know that a row of a matrix in C is a vector. I thought about doing so but as always my logic is wrong.
#define TAMANHO 4
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
void receberMatriz(int matrizPRI[TAMANHO][TAMANHO]);
void ordenarMatriz(int matrizPRI[TAMANHO][TAMANHO]);
int main(void)
{
setlocale(LC_ALL, "");
int matrizPRI[TAMANHO][TAMANHO];
receberMatriz(matrizPRI);
ordenarMatriz(matrizPRI);
return 0;
}
void receberMatriz(int matrizPRI[TAMANHO][TAMANHO])
{
int lin, col;
for(lin = 0; lin < TAMANHO; lin++)
{
for(col = 0; col < TAMANHO; col++)
{
printf("Matriz Principal [%i][%i]: ", lin, col);
scanf("%i", &matrizPRI[lin][col]);
}
}
}
void ordenarMatriz(int matrizPRI[TAMANHO][TAMANHO])
{
int lin, col;
int AUX1[TAMANHO], AUX2[TAMANHO];
for(lin = 0; lin < TAMANHO; lin++)
{
for(col = 0; col == TAMANHO; col++)
{
if(matrizPRI[lin] == 1)
{
AUX1[col] = matrizPRI[col];
AUX1[col]+1;
}
else if(matrizPRI[col] == 4)
{
AUX2[col] = matrizPRI[col];
AUX2[col]+1;
}
}
}
for(lin = 0; lin < TAMANHO; lin++)
{
for(col = 0; col < TAMANHO; col++)
{
if(matrizPRI[lin] == 1)
{
matrizPRI[lin] = AUX2[col];
}
else if(matrizPRI[col == 4])
{
matrizPRI[col] == AUX1[lin];
}
}
}
for(lin = 0; lin < TAMANHO; lin++)
{
for(col = 0; col < TAMANHO; col++)
{
printf("[%i] "), matrizPRI[lin][col];
}
printf("\n");
}
}
How can I exchange a row of an array with a column? The switch would be made from a single row and a single column, so I do not believe to use Bubble Sort. Someone gives a light to clear this mind...
what exchanging the values of the first row with the values of the last column has to do with Bubble Sort? Your question is a bit confusing. Can provide an example of the input matrix and the expected result for that matrix?
– mercador
I’m really going to try to rephrase the question, I was kind of hot-headed for not finding the logic. I will put the statement of the question: Construct an algorithm to read a 4 x 4 matrix and exchange the values of the 1st row for those of the 4th column, vice versa. Write the obtained matrix at the end.
– user70896
You can do something recursive, thus taking control of each element of the row and column to be able to exchange them safely. Recursion for when you cannot find the next row/column element.
– Leonardo Rodrigues