-
Notifications
You must be signed in to change notification settings - Fork 2
/
Diagonal_Difference.cpp
51 lines (40 loc) · 1011 Bytes
/
Diagonal_Difference.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//============================================================================
//problem link: https://www.hackerrank.com/challenges/diagonal-difference
// Name : Diagonal_Difference.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
int sumd1=0;
int sumd2=0;
cin >> n;
int k;
int arr [n][n];
for(int i=0; i<n;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
k=n-1;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)
sumd1+=arr[i][j];
}
sumd2+=arr[i][k];
k--;
}
int difference=0;
difference=sumd1-sumd2;
cout<<abs(difference);
return 0;
}