1
Create an algorithm that loads a 12 x 4 matrix with the sales values of a store, in which each row represents one month of the year, and each column, one week of the month.
For simplification purposes consider that each month has only 4 weeks. Calculate and print:
- Total sold in each month of the year;
- Total sold each 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;
}