Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Z_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "удалить все столбцы, в которых первый элемент больше последнего";
- Console.Write("Ведите натуральное число, n= ");
- int n =EnterInt();
- Console.Write("Ведите натуральное число, m= ");
- int m = EnterInt();
- int test = m;
- int[,] arr = new int[n, m];
- FillingArray(arr);
- Display(arr);
- Checking(arr, ref test);
- Console.WriteLine("**************");
- SetToZero(arr, test);
- Display(arr);
- Console.ReadKey();
- }
- static void FillingArray(int[,] arr)
- {
- Random Rand = new Random();
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- arr[i, j] = Rand.Next(9);
- }
- }
- }
- static void Display(int[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- Console.Write("{0} ", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Checking(int[,] arr, ref int test)
- {
- int temp = arr.GetLength(1);
- for (int j = 0; j < temp; j++)
- {
- if (arr[0, j] > arr[arr.GetLength(0) - 1, j])
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int k = j; k < temp - 1; k++)
- {
- Swap(ref arr[i, k], ref arr[i, k + 1]);
- }
- }
- j--;
- temp--;
- test--;
- }
- }
- }
- static void SetToZero(int[,] arr, int test)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = test; j < arr.GetLength(1); j++)
- {
- arr[i, j] = 0;
- }
- }
- }
- static void Swap(ref int a, ref int b)
- {
- int temp = a;
- a = b;
- b = temp;
- }
- static int EnterInt()
- {
- int value;
- bool result = false;
- result = int.TryParse(Console.ReadLine(), out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- result = int.TryParse(Console.ReadLine(), out value);
- }
- while (!result);
- }
- return value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement