• Дана матрица размера M ´ N. Поменять местами столбцы, содержащие минимальный и максимальный элементы матрицы.


    На C# пожалуйста, как менять элементы понимаю, а как записывать все элементы столбца куда то - нет

Ответы 1

  • static double[,] Input()         {             Console.Write("Введите размерность массива:n=");             int n = int.Parse(Console.ReadLine());             Console.Write("m=");             int m = int.Parse(Console.ReadLine());             double[,] a = new double[n, m];             Console.WriteLine("Введите элементы массива:");             for (int i = 0; i < a.GetLength(0); i++)                 for (int j = 0; j < a.GetLength(1); j++)                 {                     Console.Write("a[{0},{1}]=", i, j);                     a[i, j] = double.Parse(Console.ReadLine());                 }             return a;         }         static void Print(double[,] a)         {             for (int i = 0; i < a.GetLength(0); i++, Console.WriteLine())                 for (int j = 0; j < a.GetLength(1); j++)                     Console.Write("{0,3}", a[i, j]);         }         static void FindSum(double[,] arr, ref int sum)         {             for (int i = 0; i < arr.GetLength(0); i++)                 if (arr[i, 0] < 0)                     sum++;         }         static void FindMin(double[,] arr, int sum, ref int indMin)         {             int temp = 0;             for (int j = 1; j < arr.GetLength(1); j++)             {                 for (int i = 0; i < arr.GetLength(0); i++)                     if (arr[i, j] < 0)                         temp++;                 if (temp < sum && temp != 0)                 {                     sum = temp;                     indMin = j;                 }                 temp = 0;             }         }         static void FindMax(double[,] arr, int sum, ref int indMax)         {             int temp = 0;             for (int j = 1; j < arr.GetLength(1); j++)             {                 for (int i = 0; i < arr.GetLength(0); i++)                     if (arr[i, j] < 0)                         temp++;                 if (temp > sum)                 {                     sum = temp;                     indMax = j;                 }                 temp = 0;             }         }         static void Change(double[,] arr, int min, int max)         {             double temp;             for (int i = 0; i < arr.GetLength(0); i++)             {                 temp = arr[i, min];                 arr[i, min] = arr[i, max];                 arr[i, max] = temp;             }         }         static void Main(string[] args)         {             double[,] arr = Input();             Console.WriteLine("Исходная матрица:");             Print(arr);             int sum, indMin, indMax;             sum = indMin = indMax = 0;             FindSum(arr, ref sum);             FindMin(arr, sum, ref indMin);             FindMax(arr, sum, ref indMax);             Change(arr, indMin, indMax);             Console.WriteLine("Измененная матрица:");             Print(arr);             Console.ReadKey();         }

    0

  • Добавить свой ответ

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years