Почему не считается след матрицы? - C#
Формулировка задачи:
Не считает след матрицы, не понимаю почему. Помогите найти ошибку?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cons
{
class Program
{
static void Main(string[] args)
{
Console.Write("Введите n: ");
int n = int.Parse(Console.ReadLine());
Console.Write("Введите m: ");
int m = int.Parse(Console.ReadLine());
Console.WriteLine("Заполнение матрицы:");
int[,] mas = new int[n, m];
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
mas[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.WriteLine("Полученная матрица:");
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
Console.Write(mas[i, j] + "\t");
}
Console.WriteLine("\n");
}
int summa = 0;
for (int i = 0; i < n; i++)
{
summa += mas[i, i];
summa += mas[i, n - i];
}
Console.WriteLine(summa);
Console.ReadKey();
}
}
}Решение задачи: «Почему не считается след матрицы?»
textual
Листинг программы
mas[i, j] = Convert.ToInt32(Console.ReadLine());