repl.it
@FelishaMiranda/

Diagonal Difference

C

No description

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <string.h>

int main() {
  int i, j, k, l, n;
  int a=0, b=0;
  int arr[101][101];
  int sama = 0;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d", &arr[i][j]);
      getchar();
    }
  }

  for(i=0; i<n; i++){
    a+= arr[i][i];
    b+= arr[i][n-i-1];
  }

  if(a<b){
    printf("%d\n", b-a);
  } else if(b<a){
    printf("%d\n", a-b);
  } else{
    printf("0\n");
  }



}