Is the matrix printing the same values for all indexes, why?

1

Create an algorithm that loads a 12 x 4 matrix with sales figures for a store, where each row represents a month of the year, and each column, a week of the month.

For the sake of simplicity, consider that each month has only 4 weeks. Calculate and print:
- Total sold in each month of the year;
- Total sold every week throughout the year;
- Total sold in the year.

#include <stdio.h>

int main(){
    int matriz[12][4];
    int linha, coluna;
    int totalMes[12];
    int totalSemana[48];
    int total = 0;

    for(linha=0; linha<12; linha++){
        for(coluna=0; coluna<4; coluna++){
            scanf("%d", &matriz[linha][coluna]);
        }
    }

    for(linha=0; linha<12; linha++){
        for(coluna=0; coluna<4; coluna++){          
            totalMes[linha] += matriz[linha][coluna];

            totalSemana[coluna] += matriz[linha][coluna];

            total += totalMes[linha] + totalSemana[coluna];
        }
    }

    for(linha=0; linha<12; linha++){
        printf("Total vendido no mês %d = %d:\n", linha+1, totalMes[linha]);

        for(coluna=0; coluna<4; coluna++){
            printf("LINHA = %d e COLUNA = %d\n", linha, coluna);
            printf("Total vendido na semana %d = %d:\n", coluna+1, totalSemana[coluna]);        
        }
        printf("\n\n");
    }

    printf("Total vendido no ano = %d:\n", total);

    return 0;
}
    
asked by anonymous 23.03.2017 / 15:30

1 answer

1

Dude, I do not see any assignment to your variables, is this correct?

        for(linha=0; linha<12; linha++){
            for(coluna=0; coluna<4; coluna++){
                scanf("%d", &matriz[linha][coluna]);
            }
        }

        for(linha=0; linha<12; linha++){
            for(coluna=0; coluna<4; coluna++){

                totalMes[linha] += matriz[linha][coluna];

                totalSemana[coluna] += matriz[linha][coluna];

                total += totalMes[linha] + totalSemana[coluna];
            }

        }

where you assigned a value in the array variable [row] [column]?

explains this to me so far its matrix has been null and void. then add empty with empty result = empty

= D

    
23.03.2017 / 17:27