Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- // n*m
- // Удалить строки содерж макс элементы матрицы
- // использовать метод
- namespace ConsoleApp1
- {
- class Program
- {
- public static void FindAndDelete(ref int[,] a)
- {
- int max = Int32.MinValue;
- for (int j = 0; j < a.GetLength(dimension: 1); j++)
- {
- for (int i = 0; i < a.GetLength(dimension: 0); i++)
- {
- if (a[i, j] > max)
- max = a[i, j];
- }
- }
- for (int i = 0; i < a.GetLength(dimension: 0); i++)
- {
- bool FoundMax = false;
- for (int j = 0; j < a.GetLength(dimension: 1); j++)
- {
- if (a[i, j] == max)
- FoundMax = true;
- }
- if (!FoundMax)
- {
- for (int jj = 0; jj < a.GetLength(dimension: 1); jj++)
- {
- Console.Write("{0,6}", a[i,jj]);
- }
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("Строка удалена");
- }
- FoundMax = false;
- }
- }
- static void CreateMatrix(ref int[,] a)
- {
- Random r = new Random(1231471366);
- Console.WriteLine("Матрица");
- for (int i = 0; i < a.GetLength(dimension: 0); i++)
- {
- for (int j = 0; j < a.GetLength(dimension: 1); j++)
- {
- a[i, j] = r.Next(-2, 10);
- Console.Write("{0, 6}", a[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- const int n = 4;
- const int m = 5;
- int[,] array = new int[n, m];
- CreateMatrix(ref array);
- Console.WriteLine();
- Console.ForegroundColor = ConsoleColor.Green;
- FindAndDelete(ref array);
- Console.Read();
- }
- }
- }
Add Comment
Please, Sign In to add comment