Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- int main() {
- int tam, i, j, contCol=0, contLin =0, contFLin = 0, contFCol = 0, contDa =0, contDb = 0;
- scanf("%d", &tam);
- int __vetNumbers[tam][tam];
- for(i=0; i<tam; i++) {
- for(j=0; j<tam; j++) {
- scanf("%d", &__vetNumbers[i][j]);
- }
- }
- for(i=0; i<tam; i++) {
- for(j=0; j<tam; j++) {
- contLin = contLin + __vetNumbers[i][j];
- }
- if(contFLin == 0) {
- contFLin = contLin; }
- if(contFLin != contLin) {
- printf("-1");
- return;
- }
- contLin = 0;
- }
- for(i=0; i<tam; i++) {
- for(j=0; j<tam; j++) {
- contCol = contCol + __vetNumbers[j][i];
- }
- if(contFCol == 0) {
- contFCol = contCol; }
- if(contFCol != contCol) {
- printf("-1");
- return;
- }
- contCol = 0;
- }
- for(i=0; i<tam; i++) {
- for(j=0; j<tam; j++) {
- if(i == j) {
- contDa = contDa + __vetNumbers[i][j];
- }
- }
- }
- if(contDa != contFCol) {
- printf("-1");
- return;
- }
- for(i=tam-1; i>=0; i--) {
- for(j=tam-1; j>=0; j--) {
- if(i == j) {
- contDb = contDb + __vetNumbers[i][j];
- }
- }
- }
- if(contDb != contFCol) {
- printf("-1");
- return;
- }
- printf("%d\n", contFCol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement