1
I need to create an algorithm that reads the dimensions of a matrix, read the values to be placed in the matrix, with a vector calculate the sum of the values of each row and print the matrix and the vector.
This float soma
computes the total sum of the entire matrix, but need to calculate the sum of each line.
int main() {
int L , C , linha = 0 , coluna = 0;
float soma = 0;
printf("\nDigite o numero de linhas da matriz: ");
scanf("%d",&L);
printf("\nDigite o numero de colunas da matriz: ");
scanf("%d",&C);
float matriz[L][C];
for(linha = 0; linha < L; linha++){
for(coluna = 0; coluna < C; coluna++){
printf("\nDigite o %d valor para a %d linha: ",coluna + 1, linha + 1);
scanf("%f",&matriz[linha][coluna]);
soma = soma + matriz[linha][coluna];
}
}
for (linha = 0; linha < L; linha++){
for(coluna = 0; coluna < C; coluna++){
printf("%5.2f ",matriz[linha][coluna]);
}
printf("\n\n");
}
printf("\n\nA soma total eh %5.2f\n\n\n",soma);
system("pause");
return 0;
}
Create a sum vector and place the sum of the lines in each position, that’s it?
– Fábio Morais
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero