-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.cpp
More file actions
46 lines (45 loc) · 810 Bytes
/
matrix.cpp
File metadata and controls
46 lines (45 loc) · 810 Bytes
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
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>arr[i][j];
}
}
int rsum=0,lsum=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
rsum = rsum + arr[i][j];
if(i==((n/2)))
{
lsum=lsum+arr[i][j];
}
}
else if((j==(i-(n-1))||i==(j-(n-1)))&&(i!=j))
{
lsum=lsum+arr[i][j];
}
}
cout<<rsum<<" "<<lsum<<endl;
}
int res;
if(lsum>rsum)
{
res=lsum-rsum;
}
else {
res=rsum-lsum;
}
cout<<res<<endl;
return 0;
}