Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define n 4
- #define m 5
- int main(void)
- {
- int A[m][n],i,j,sl,sc,k;
- // A= {{1,2,3},{4,5,6},}
- for (i=0;i<n;i++) // definindo os elementos
- {
- for (j=0;j<m;j++)
- {
- A[i][j]=rand() % (m*n);
- }
- }
- for (i=0;i<n;i++) // apresentando a matriz
- {
- for (j=0;j<m;j++)
- {
- printf("%d ",A[i][j]);
- if (j==(m-1))
- {printf("\n");}
- }
- }
- for (i=0;i<n;i++) // somando elementos de cada linha
- {
- sl=0;
- for (j=0;j<m;j++)
- {
- sl+=A[i][j];
- }
- printf("Soma %d-ésima linha: %d \n",i+1,sl);
- }
- for (j=0;j<m;j++) // somando elementos de cada coluna
- {
- sc=0;
- for (i=0;i<n;i++)
- {
- sc+=A[i][j];
- }
- printf("Soma %d-ésima coluna: %d \n",j+1,sc);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement