daily pastebin goal
41%
SHARE
TWEET

Problem 2. Diagonal Difference

fight90 Jan 29th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SoftUniNetCore
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             /*
  12.          Write a program that finds the difference between the sums of the square matrix diagonals (absolute value).
  13.             */
  14.  
  15.             int size = int.Parse(Console.ReadLine());
  16.            
  17.             int[,] matrix = new int[size,size];
  18.  
  19.             for (int i = 0; i < size; i++)
  20.             {
  21.                int[] arr = Console.ReadLine().Split(" ,".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  22.                 for (int a = 0; a < arr.Length; a++)
  23.                 {
  24.                     matrix[i,a] = arr[a];
  25.                 }
  26.             }
  27.             int sumOfFirstDiagonal = 0;
  28.             int sumOfSecondDiagonal = 0;
  29.             for (int i = 0; i < size; i++)
  30.             {
  31.                 sumOfFirstDiagonal += matrix[i,i];
  32.                 sumOfSecondDiagonal += matrix[ i, size-1 - i];
  33.             }
  34.             Console.WriteLine(Math.Abs(sumOfFirstDiagonal-sumOfSecondDiagonal));
  35.            
  36.         }
  37.     }
  38. }
RAW Paste Data
Pastebin PRO WINTER Special!
Get 40% OFF Pastebin PRO accounts!
Top