Beispiel #1
0
        static void Main(string[] args)
        {
            do
            {
                int N;
                do
                {
                    Console.Write("Введите число линейных уравнений: ");
                }while (!int.TryParse(Console.ReadLine(), out N));

                LinearEquation[] equations = new LinearEquation[N];

                Random rnd = new Random();
                for (int i = 0; i < N; i++)
                {
                    double a = -10 + rnd.NextDouble() * 20;
                    double b = -10 + rnd.NextDouble() * 20;
                    double c = -10 + rnd.NextDouble() * 20;
                    try
                    {
                        equations[i] = new LinearEquation(a, b, c);
                    }
                    catch (Exception)
                    {
                        i--;
                        continue;
                    }
                }

                for (int i = 0; i < equations.Length - 1; i++)
                {
                    double min  = equations[i].Root;
                    int    mini = i;
                    for (int j = i + 1; j < equations.Length; j++)
                    {
                        if (min > equations[j].Root)
                        {
                            min  = equations[j].Root;
                            mini = j;
                        }
                    }
                    if (mini == i)
                    {
                        continue;
                    }
                    LinearEquation temp = equations[i];
                    equations[i]    = equations[mini];
                    equations[mini] = temp;
                }
                Console.Write("\n");

                for (int i = 0; i < equations.Length; i++)
                {
                    Console.WriteLine($"Уравнение №{i+1,2}: {equations[i]}");
                }

                Console.WriteLine("Нажмите ESC, чтобы выйти");
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
Beispiel #2
0
        static void Main()
        {
            do
            {
                Console.Clear();

                Console.Write("Enter the value of N: ");

                if (!uint.TryParse(Console.ReadLine(), out uint N))
                {
                    Console.WriteLine("Incorrect input.");
                    Console.WriteLine("Press any key to continue.");

                    Console.ReadKey();
                    continue;
                }

                LinearEquation[] equations = new LinearEquation[N];

                for (int index = 0; index < equations.Length; index++)
                {
                    Console.WriteLine();

                    equations[index] = new LinearEquation();
                    Console.WriteLine(equations[index].ToString());
                }

                equations = equations.OrderBy(item => item.X).ToArray();

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("\nSort is complete.");
                Console.ResetColor();

                Array.ForEach(equations, item => Console.WriteLine($"\n{item}"));

                Console.WriteLine("\nPress Esc to exit or another key to continue");
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }