Advertisement
chefache

Untitled

Sep 26th, 2019
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Primary_diagonal
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int matrixSize = int.Parse(Console.ReadLine());
  10.  
  11. var matrix = new int[matrixSize, matrixSize];
  12. long primaryDiagonalSum = 0;
  13.  
  14. for (int row = 0; row < matrixSize; row++)
  15. {
  16. var numbers = Console.ReadLine();
  17. var singleNum = numbers.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  18. for (int col = 0; col < matrixSize; col++)
  19. {
  20. matrix[row, col] = int.Parse(singleNum[col]);
  21. }
  22. }
  23. for (int row = 0; row < matrix.GetLength(0); row++)
  24. {
  25. for (int col = 0; col < matrix.GetLength(1); col++)
  26. {
  27. primaryDiagonalSum += matrix[row, col] + matrix[row + 1, col + 1] + matrix[row + 2, col + 2];
  28. Console.WriteLine(primaryDiagonalSum);
  29. return;
  30. }
  31. }
  32.  
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement