Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- var n = int.Parse(Console.ReadLine());
- long[][] matrix = new long[n][];
- // Filling the Matrix
- for (int row = 0; row < n; row++)
- {
- matrix[row] = Console.ReadLine().Split().Select(long.Parse).ToArray();
- }
- // Sum the first diagonal of Matrix
- long firstDiagonalSum = 0;
- for (int row = 0; row < n; row++)
- {
- for (int col = 0; col < n; col++)
- {
- if (row == col)
- {
- firstDiagonalSum += matrix[row][col];
- }
- }
- }
- // Sum the second diagonal of Matrix
- long secondDiagonalSum = 0;
- for (int row = 0; row < n; row++)
- {
- for (int col = n - 1; col >= 0; col--)
- {
- if (col == Math.Abs(row - n + 1))
- {
- secondDiagonalSum += matrix[row][col];
- }
- }
- }
- Console.WriteLine(Math.Abs(firstDiagonalSum - secondDiagonalSum));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement