private static LinearEquation[] GenerateLinearEquations(int n) { var linearEquations = new LinearEquation[n]; for (var i = 0; i < linearEquations.Length; i++) { linearEquations[i] = new LinearEquation(Random.Next(-10, 11), Random.Next(-10, 11), Random.Next(-10, 11)); } return(linearEquations); }
static void Main(string[] args) { do { int N; do { Console.WriteLine("Введите N"); } while (!int.TryParse(Console.ReadLine(), out N)); LinearEquation[] linearEquation = new LinearEquation[N]; // Печать несортированного массива. Console.WriteLine("Неотсортированные решения: " + Environment.NewLine); for (int i = 0; i < linearEquation.Length; i++) { Random random = new Random(); linearEquation[i] = new LinearEquation(random.Next(-10, 10), random.Next(-10, 10), random.Next(-10, 10)); Console.WriteLine($"A:{linearEquation[i].GetA()}, B:{linearEquation[i].GetB()}, C:{linearEquation[i].GetC()}, Result: {linearEquation[i].GetResult()}"); } // Сортировка пузырьком. for (int i = 0; i < linearEquation.Length - 1; i++) { for (int k = 0; k < linearEquation.Length - 1; k++) { if (linearEquation[i].GetResult() > linearEquation[i + 1].GetResult()) { LinearEquation tmp = linearEquation[i]; linearEquation[i] = linearEquation[i + 1]; linearEquation[i + 1] = tmp; } } } Console.WriteLine("Отсортированные решения: " + Environment.NewLine); for (int i = 0; i < linearEquation.Length; i++) { Console.WriteLine($"A:{linearEquation[i].GetA()}, B:{linearEquation[1].GetB()}, C:{linearEquation[i].GetC()}, Result: {linearEquation[i].GetResult()}"); } Console.WriteLine("Для выхода нажмите ESC, для продолжения Enter..."); } while (Console.ReadKey(true).Key != ConsoleKey.Escape); }
static void Main(string[] args) { while (true) { Random rnd = new Random(); Console.WriteLine("Enter n"); int n = int.Parse(Console.ReadLine()); LinearEquation[] arr = new LinearEquation[n]; for (int i = 0; i < arr.Length; i++) { arr[i] = new LinearEquation(rnd.Next(-10, 11), rnd.Next(-10, 11), rnd.Next(-10, 11)); Console.WriteLine(arr[i]); } Console.WriteLine(); for (int i = 0; i < arr.Length - 1; i++) { for (int j = i + 1; j < arr.Length; j++) { if (arr[i].Root() < arr[j].Root()) { LinearEquation temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } foreach (LinearEquation i in arr) { Console.WriteLine(i); } Console.WriteLine("Enter 0 to escape"); string s = Console.ReadLine(); if (s == "0") { break; } } }