Hi, ive been having some problem here, can't figure out whats wrong...
when i type in 2 2 the matrix should be a 2x2 one, so then i type in the numbers 1 2 3 4, so the matrix first line is 1 2 and second line is 3 4, the sum of the diagonal numbers should be 1+4 = 5, but i keep getting 10 as answer, whats wrong?
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
int L, C, soma = 0;
scanf("%d", &L);
scanf("%d", &C);
int matriz[L][C];
for(int i=0; i<L; i++){
for(int j=0; j<C; j++){
scanf("%d", &matriz[i][j]);
}
}
for(int i=0; i<L; i++){
for(int j=0; j<C; j++){
soma += matriz[i][i];
}
}
printf("%d\n", soma);
system("pause");
return 0;
}