Last active
August 29, 2015 14:02
-
-
Save leonardocordeiro/b36ef5767538fe770eef to your computer and use it in GitHub Desktop.
maior elemento diagonal principal, soma diagonal secundária
This file contains hidden or 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> | |
#include <stdlib.h> | |
main() | |
{ | |
int matriz[3][3]; | |
int i, j; | |
int maiorDiagonalPrincipal, diagonalSecundaria; | |
maiorDiagonalPrincipal = scanf("%i", &matriz[0][0]); | |
diagonalSecundaria = 0; | |
for(i = 0; i < 3; i++) | |
for(j = 0; j < 3; j++) | |
if(i != 0 || j != 0) { | |
scanf("%i", &matriz[i][j]); | |
if(i == j && matriz[i][j] > maiorDiagonalPrincipal) | |
maiorDiagonalPrincipal = matriz[i][j]; | |
if(i + j == 2) | |
diagonalSecundaria += matriz[i][j]; | |
} | |
printf("%s %i \n", "Maior elemento: ", maiorDiagonalPrincipal); | |
printf("%s %i", "Soma diagonal secundaria: ", diagonalSecundaria); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment