#include <stdio.h>
#include <string.h>
int main( ) {
int linhas , colunas;
printf ( "\n Digite o numero de linhas da matriz: " ) ; printf ( "\n Digite o numero de colunas da matriz: " ) ; float matriz[ linhas] [ colunas] ;
float soma = 0 ;
float somaLinhas[ linhas] ;
memset ( somaLinhas
, 0 , sizeof ( somaLinhas
) ) ; for ( int linha = 0 ; linha < linhas; linha++ ) {
for ( int coluna = 0 ; coluna < colunas; coluna++ ) {
printf ( "\n Digite o %d valor para a %d linha: " , coluna
+ 1 , linha
+ 1 ) ; scanf ( "%f" , & matriz
[ linha
] [ coluna
] ) ; soma += matriz[ linha] [ coluna] ;
somaLinhas[ linha] += matriz[ linha] [ coluna] ;
}
}
for ( int linha = 0 ; linha < linhas; linha++ ) {
for ( int coluna
= 0 ; coluna
< colunas
; coluna
++ ) printf ( "%5.2f " , matriz
[ linha
] [ coluna
] ) ; }
for ( int linha
= 0 ; linha
< linhas
; linha
++ ) printf ( "\n A soma da linha %d eh %5.2f" , linha
, somaLinhas
[ linha
] ) ; printf ( "\n A soma total eh %5.2f" , soma
) ; }
//https://pt.stackoverflow.com/q/328211/101
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCmludCBtYWluKCkgewoJaW50IGxpbmhhcyAsIGNvbHVuYXM7CglwcmludGYoIlxuRGlnaXRlIG8gbnVtZXJvIGRlIGxpbmhhcyBkYSBtYXRyaXo6ICIpOwoJc2NhbmYoIiVkIiwgJmxpbmhhcyk7CglwcmludGYoIlxuRGlnaXRlIG8gbnVtZXJvIGRlIGNvbHVuYXMgZGEgbWF0cml6OiAiKTsKCXNjYW5mKCIlZCIsICZjb2x1bmFzKTsKCWZsb2F0IG1hdHJpeltsaW5oYXNdW2NvbHVuYXNdOwoJZmxvYXQgc29tYSA9IDA7CglmbG9hdCBzb21hTGluaGFzW2xpbmhhc107CgltZW1zZXQoc29tYUxpbmhhcywgMCwgc2l6ZW9mKHNvbWFMaW5oYXMpKTsKCWZvciAo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