Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Primary_diagonal
- {
- class Program
- {
- static void Main(string[] args)
- {
- int matrixSize = int.Parse(Console.ReadLine());
- var matrix = new int[matrixSize, matrixSize];
- long primaryDiagonalSum = 0;
- for (int row = 0; row < matrixSize; row++)
- {
- var numbers = Console.ReadLine();
- var singleNum = numbers.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
- for (int col = 0; col < matrixSize; col++)
- {
- matrix[row, col] = int.Parse(singleNum[col]);
- }
- }
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- primaryDiagonalSum += matrix[row, col] + matrix[row + 1, col + 1] + matrix[row + 2, col + 2];
- Console.WriteLine(primaryDiagonalSum);
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement