Last active
June 16, 2016 14:07
-
-
Save graifman/f8f2ef47ced94f6d006120a622fccea3 to your computer and use it in GitHub Desktop.
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> | |
void soma (int *m[4][4]) | |
{ | |
int i, j; | |
int soma_principal=0; | |
int soma_secundaria=0; | |
for(i=0; i<4; i++){ | |
for(j=0; j<4; j++){ | |
if(j==i){ | |
soma_principal=soma_principal+*m[i][j]; | |
} | |
} | |
} | |
for(i=0; i<4; i++){ | |
for(j=0; j<4; j++){ | |
if((j==i-1)&&(i>j)){ | |
soma_secundaria=soma_secundaria+*m[i][j]; | |
} | |
} | |
} | |
printf("Soma matriz principal = %d\n",soma_principal); | |
printf("Soma matriz secundaria = %d\n",soma_secundaria); | |
} | |
int main() | |
{ | |
int i,j; | |
int matriz[4][4]; | |
for(i=0; i<4; i++){ | |
for(j=0; j<4; j++){ | |
printf("Insira o numero da linha %d coluna %d\n",i+1,j+1); | |
scanf("%d",&matriz[i][j]); | |
} | |
} | |
for(i=0; i<4; i++){ | |
for(j=0; j<4; j++){ | |
printf("%d\t",matriz[i][j]); | |
} | |
printf("\n"); | |
} | |
soma(&matriz); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment