Advertisement
Bubeto

Untitled

Jan 22nd, 2020
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace Diagonal_Difference
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. int[,] matrix = new int[n, n];
  11. int diagonal = 0;
  12. for (int row = 0; row < matrix.GetLength(0); row++)
  13. {
  14. int[] rows = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  15.  
  16. for (int col = 0; col < matrix.GetLength(1); col++)
  17. {
  18. matrix[row, col] = rows[col];
  19.  
  20. }
  21.  
  22. }
  23.  
  24. int primaryDiagonal = 0;
  25.  
  26. for (int i = 0; i < n; i++)
  27. {
  28. primaryDiagonal += matrix[i, i];
  29.  
  30. }
  31. for (int i = 0; i < n; i++)
  32. {
  33. diagonal += matrix[n - i - 1, i];
  34. }
  35.  
  36. int difference = diagonal - primaryDiagonal;
  37.  
  38. Console.WriteLine(Math.Abs(difference));
  39.  
  40.  
  41. }
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement