forked from seeditsolution/pythonprogram
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagonaldifference
More file actions
Latest commit
22 lines (16 loc) · 427 Bytes
/
Copy pathdiagonaldifference
File metadata and controls
22 lines (16 loc) · 427 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def diagonalDifference(arr) #function accepting a 2d array
sum1=0
sum2=0
res=0
for i in range(0,len(arr)):
sum1=sum1+arr[i][i]
sum2=sum2+arr[i][(len(arr)-1)-i]
res=sum1-sum2
return abs(res)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip) #size
arr = []
for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))
print( diagonalDifference(arr))