Created
June 4, 2017 15:28
-
-
Save marcoscastro/c04fbee9b5d18f12c21af3aa814e6df4 to your computer and use it in GitHub Desktop.
Soma dos elementos da matriz diagonal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(int argc, char *argv[]) | |
{ | |
int mat[2][2] = {{1,2}, {3,4}}; | |
int i, j, soma = 0; | |
for(i = 0; i < 2; i++) | |
{ | |
for(j = 0; j < 2; j++) | |
{ | |
if(i == j) | |
{ | |
soma += mat[i][j]; | |
} | |
} | |
} | |
printf("Soma: %d", soma); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment