Hola buenas,
would like to know why this little program does not work for me.
I have to: Read the upper triangle of the matrix and print it on the screen.
At the moment I have this, but the problem is that at the time of printing / reading (I'm not sure where the problem is), the matrix is like I'm left in an infinite loop and does not do anything.
#include <stdio.h>
#define DIM 3
void leer_matriz_superior (float matriz [DIM][DIM]);
void imprimir_matriz_superior (float matriz [DIM][DIM]);
void main () {
float matriz [DIM][DIM];
printf ("Introduce una matriz 3x3: ");
leer_matriz_superior (matriz);
imprimir_matriz_superior (matriz);
}
// Función 1.
void leer_matriz_superior (float matriz [DIM][DIM]) {
int i, j;
for (i = 0; i = DIM -2; i ++) {
for (j = i + 1; j = DIM - 1; j ++) {
scanf ("%f", &matriz [i][j]);
}
}
}
// Función 2.
void imprimir_matriz_superior (float matriz [DIM][DIM]) {
int i, j;
for (i = 0; i = DIM - 2; i ++) {
for (j = i + 1; j = DIM - 1; j ++) {
printf ("%6.0f", matriz [i][j]);
}
printf ("\n");
}
}
The compiler does not give an error, and I have reviewed the loop conditions and I think they are correct, any solution?
Greetings and thanks in advance.
Edited:
#include <stdio.h>
#define DIM 3
void leer_matriz_superior (float matriz [DIM][DIM]);
void imprimir_matriz_superior (float matriz [DIM][DIM]);
void main () {
float matriz [DIM][DIM];
printf ("Introduce una matriz 3x3: ");
leer_matriz_superior (matriz);
imprimir_matriz_superior (matriz);
}
// Funció 1.
void leer_matriz_superior (float matriz [DIM][DIM]) {
int i, j;
for (i = 0; i < DIM; i ++) {
for (j = 0; j < DIM; j ++) {
scanf ("%f", &matriz [i][j]);
}
}
}
// Funció 2.
void imprimir_matriz_superior (float matriz [DIM][DIM]) {
int i, j;
for (i = 0; i = DIM - 2; i ++) {
for (j = i + 1; j = DIM - 1; j ++) {
printf ("%6.0f", matriz [i][j]);
}
printf ("\n");
}
}