Дана матрица. Надо поменять местами первый и последний столбцы - C#
Формулировка задачи:
Листинг программы
- namespace матрицы
- {
- class Program
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Количество строк");
- int m = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Количество столбцов");
- int n = Convert.ToInt32(Console.ReadLine());
- int[,] mat = new int[m, n];
- Random rnd = new Random();
- Console.WriteLine();
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- mat[i, j] = rnd.Next(-50, 50);
- Console.Write(mat[i, j] + "\t");
- }
- Console.WriteLine();
- }
- int prom=0;
- for (int i=0; i<m; i++)
- {
- prom=mat[i,0];
- mat[i,0]=mat[i,n];
- mat[i,n]=prom;
- prom=0;
- }
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(mat[i, j] + "\t");
- }
- Console.WriteLine();
- }
- Console.ReadKey(true);
- }
- }
- }
Решение задачи: «Дана матрица. Надо поменять местами первый и последний столбцы»
textual
Листинг программы
- for (int i=0; i<m; i++)
- {
- prom=mat[i,0];
- mat[i,0]=mat[i,n];
- mat[i,n]=prom;
- prom=0;
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д