Skip to content

Instantly share code, notes, and snippets.

@marcoscastro
Created June 4, 2017 15:28
Show Gist options
  • Save marcoscastro/c04fbee9b5d18f12c21af3aa814e6df4 to your computer and use it in GitHub Desktop.
Save marcoscastro/c04fbee9b5d18f12c21af3aa814e6df4 to your computer and use it in GitHub Desktop.
Soma dos elementos da matriz diagonal
#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