Advertisement
Guest User

Diagonal Difference

a guest
May 31st, 2017
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace HomeWork
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. var matrix = new double[n][];
  12. for (int rowsIndex = 0; rowsIndex < n; rowsIndex++)
  13. {
  14. var nums = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
  15. matrix[rowsIndex] = nums;
  16. }
  17. double diagonalSum1 = 0;
  18. for (int i = 0; i < n; i++)
  19. diagonalSum1 += matrix[i][i];
  20.  
  21. double diagonalSum2 = 0;
  22. int start = n - 1;
  23. for (int i = 0; i < n; i++)
  24. {
  25. diagonalSum2 += matrix[i][start];
  26. start--;
  27. }
  28. Console.WriteLine(Math.Abs(diagonalSum1 - diagonalSum2));
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement