Ошибка при чтении из файла матрицы

Есть вот такой код

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApp18
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] array;
            using (var sr = new StreamReader(@"D:\Matrix.txt"))
            {
                array = sr.ReadToEnd().Split().Select(int.Parse).ToArray();
            }

            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    Console.Write(array[i] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-----------------");
            
            for (int i = 0; i < array.GetLength(0); i++)
            {
                int cnt = 0;
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    if (j < array.GetLength(1) - 1)
                    {
                        cnt += array[i];
                    }
                    else
                    {

                        array[i] = cnt / (array.GetLength(1) - 1);
                    }
                    Console.Write(array[i] + " ");
                }
                Console.WriteLine();
            }
            Console.ReadLine();

        }
    }
}

Само задание Консольное приложение для обработки матриц.Исходным является файл с элементами матрицы Необходимо считать исходные данные, вывести их на экран для просмотра и выполнить обработку. Результат обработки вывести на экран и в файл. Преобразовать матрицу таким образом, чтобы последний элемент каждой строки был равен среднему арифметическому предыдущих элементов той же строки.


Ответы (0 шт):