-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
31 lines (23 loc) · 885 Bytes
/
Program.cs
File metadata and controls
31 lines (23 loc) · 885 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
using System;
namespace Diagonal_Difference {
class Program {
public static int DiagonalDifference(int[][] ar) {
int firstDiagonal = 0;
int secondDiagonal = 0;
for (int i = 0; i < ar.Length; i++) {
firstDiagonal = firstDiagonal + ar[i][i];
secondDiagonal = secondDiagonal + ar[i][(ar.Length - 1) - i];
}
return Math.Abs(firstDiagonal - secondDiagonal);
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[][] ar = new int[n][];
for (int i = 0; i < n; i++) {
ar[i] = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
}
int result = DiagonalDifference(ar);
Console.WriteLine(result);
}
}
}