Advertisement
Schknheit

soma dos elementos da diagonal pricipal usando laço

May 15th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.    
  5.     int i, j, soma = 0, mat[3][3];
  6.    
  7.     printf("Entre com quatro elementos: \n");
  8.    
  9.     for(i = 0; i < 3; i++){
  10.         for(j = 0; j < 3; j++){
  11.             scanf("%d",&mat[i][j]);
  12.         }
  13.     }
  14.    
  15.     for(i = 0; i < 3; i++){
  16.             soma = soma + mat[i][i];
  17.     }
  18.    
  19.     printf("A soma: %d", soma);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement