0
I’m solving an exercise where I type values for a matrix 3x3
, the print and also display its transpose. The problem is that I am not able to receive fractional values, and comma numbers.
The code I was able to develop is this:
#include <stdio.h>
#include <stdlib.h>
void imprime_matriz(int matriz[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %2d ",matriz[i][j]);
}
printf("\n");
}
}
void preenche_matriz(int matriz[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(" %d ",&matriz[i][j]);
}
}
}
void transposta(int matriz[3][3])
{
int i,j;
int aux[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
aux[i][j] = matriz[j][i];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
matriz [i][j] = aux[i][j];
}
}
}
int main()
{ int matriz[3][3];
printf("\nDigite os elementos da Matriz:\n\n");
preenche_matriz(matriz);
imprime_matriz(matriz);
transposta(matriz);
printf("\n");
imprime_matriz(matriz);
system("pause");
return 0;
}
Understanding "fractional values" as real numbers then is because you have declared your matrix to be integer numbers. Try declaring your matrix as float or double and not int.
– anonimo
Also note that the transpose of a matrix x[M][N] is a matrix xt[M][N] with any M and N, may or may not be equal, and therefore you can only overwrite the original matrix with the transpose in the particular case of M equal to N.
– anonimo