Advertisement
Guest User

Untitled

a guest
May 31st, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. public class Program
  9. {
  10. public static void Main()
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. long[,] matrix = new long[n,n];
  15.  
  16. long primaryDiagonal = 0;
  17. long secondaryDiagonal = 0;
  18.  
  19. for (int row = 0; row < n; row++)
  20. {
  21. int[] rowInts = Console.ReadLine().Split().Select(int.Parse).ToArray();
  22.  
  23. for (int col = 0; col < n; col++)
  24. {
  25. matrix[row, col] = rowInts[col];
  26.  
  27. if (row == col)
  28. {
  29. primaryDiagonal += rowInts[col];
  30. }
  31.  
  32. if (col == ((n - 1) - row))
  33. {
  34. secondaryDiagonal += rowInts[col];
  35. }
  36. }
  37. }
  38.  
  39. Console.WriteLine(Math.Abs(primaryDiagonal - secondaryDiagonal));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement