Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace SoftUniNetCore
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- Write a program that finds the difference between the sums of the square matrix diagonals (absolute value).
- */
- int size = int.Parse(Console.ReadLine());
- int[,] matrix = new int[size,size];
- for (int i = 0; i < size; i++)
- {
- int[] arr = Console.ReadLine().Split(" ,".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int a = 0; a < arr.Length; a++)
- {
- matrix[i,a] = arr[a];
- }
- }
- int sumOfFirstDiagonal = 0;
- int sumOfSecondDiagonal = 0;
- for (int i = 0; i < size; i++)
- {
- sumOfFirstDiagonal += matrix[i,i];
- sumOfSecondDiagonal += matrix[ i, size-1 - i];
- }
- Console.WriteLine(Math.Abs(sumOfFirstDiagonal-sumOfSecondDiagonal));
- }
- }
- }
RAW Paste Data



