Advertisement
Guest User

Untitled

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