Beispiel #1
0
        static void Main(string[] args)
        {
            Console.Write("Введите первое число: ");
            int x = int.Parse(Console.ReadLine());

            Console.Write("Введите второе число: ");
            int y       = int.Parse(Console.ReadLine());
            int greater = Utils.Greater(x, y);

            Console.WriteLine("Большим из чисел {0} и {1} является число {2}", x, y, greater);
            Console.WriteLine("До swap: \t{0} {1}", x, y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("После swap: \t{0} {1}", x, y);
            int  f;
            bool ok;

            Console.Write("Number for factorial: ");
            x  = int.Parse(Console.ReadLine());
            ok = Utils.Factorial(x, out f);
            if (ok)
            {
                Console.WriteLine("Factorial({0}) = {1}", x, f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Введите x и y");
            int x       = int.Parse(Console.ReadLine());
            int y       = int.Parse(Console.ReadLine());
            int greater = Utils.Greater(x, y);

            if (x != y)
            {
                Console.WriteLine("Наибольшим из {0} и {1} является {2}", x, y, greater);
            }
            else
            {
                Console.WriteLine("Числа равны");
            }
            Console.WriteLine("До swap: \t " + x + " " + y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("После swap: \t" + x + " " + y);
            int  f;
            bool ok;

            Console.WriteLine("Число для теста Factorial: ");
            x  = int.Parse(Console.ReadLine());
            ok = Utils.Factorial(x, out f);
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Факториал не компьютизируем");
            }
        }
        static void Main(string[] args)
        {
            int x, y, greater;

            Console.WriteLine("Enter first number: ");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter second number: ");
            y = int.Parse(Console.ReadLine());

            greater = Utils.Greater(x, y);
            Console.WriteLine("The greater value is: " + greater);

            Console.WriteLine("Before swap: " + x + "," + y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("After swap: " + x + "," + y);

            int  f;
            bool ok;

            Console.WriteLine("Number for factorial:");
            x  = int.Parse(Console.ReadLine());
            ok = Utils.Factorial(x, out f);
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            int x;
            int y;

            Console.WriteLine("Введите первое число:");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Введите второе число:");
            y = int.Parse(Console.ReadLine());
            int greater = Utils.Greater(x, y);

            Console.WriteLine("Большим из чисел {0} и {1} является {2} ", x, y, greater);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("До swap: \t" + x + " " + y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("После swap: \t" + x + " " + y);
            int  f;
            bool ok;

            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());
            // Test the factorial function
            ok = Utils.Factorial(x, out f);
            // Output factorial results
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
        }
Beispiel #5
0
        public static void Main()
        {
            int x;       // Значение первого вводимого числа
            int y;       // Значение первого вводимого числа
            int greater; // Результат из метода Greater()

            Console.WriteLine("Enter the first integer:");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the second integer:");
            y       = int.Parse(Console.ReadLine());
            greater = Utils.Greater(x, y);

            Console.WriteLine("The greater value is " + greater);
            Console.ReadKey();


            // Проверка работы метода Swap()
            Console.WriteLine("Before swap: " + x + "," + y);

            Utils.Swap(ref x, ref y);
            Console.WriteLine("After swap: " + x + "," + y);
            Console.ReadKey(); // Для удобства проверки вывода

            // Все что ниже относится к Упражнение 3

            int  f;  // Factorial result
            bool ok; // Factorial success or failure

            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());

            // Test the factorial function
            ok = Utils.Factorial(x, out f);
            // Output factorial results
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
            Console.ReadKey();
        }
Beispiel #6
0
        public static void ThirdTask()
        {
            int  result = 0;
            bool ok;

            Console.WriteLine("Number for factorial:");
            int factNumber = int.Parse(Console.ReadLine());

            isOk = Utils.Factorial(factNumber, out result);

            if (isOk)
            {
                Console.WriteLine("Factorial(" + factNumber + ") = " + result);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
        }
Beispiel #7
0
        public static void Main()
        {
            int x;       // Input value 1
            int y;       // Input value 2
            int greater; // Result from Greater()

            // Get input numbers
            Console.WriteLine("Enter first number:");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter second number:");
            y = int.Parse(Console.ReadLine());

            // Test the Greater( ) method
            greater = Utils.Greater(x, y);
            Console.WriteLine("The greater value is " + greater);
            Console.ReadKey();
            // Test the Swap method
            Console.WriteLine("Before swap: " + x + "," + y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("After swap: " + x + "," + y);
            Console.ReadKey();

            int  f;  // Factorial result
            bool ok; // Factorial success or failure

            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());

            // Test the factorial function
            ok = Utils.Factorial(x, out f);
            // Output factorial results
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
            Console.ReadKey();
        }
Beispiel #8
0
        public static void Main()
        {
            // Request two numbers and print greater of them
            int x = 0, y = 0;

            Console.WriteLine("Please input first number: ");
            try
            {
                x = int.Parse(Console.ReadLine());
                Console.WriteLine("Please input second number: ");
                y = int.Parse(Console.ReadLine());

                //Test Swap method
                Console.WriteLine("Before swap: x = {0}, y = {1}", x, y);
                Utils.Swap(ref x, ref y);
                Console.WriteLine("After swap: x = " + x + ", y = " + y);
            }
            catch (FormatException e)
            {
                Console.WriteLine(e);
            }
            int greater = Utils.Greater(x, y);

            Console.WriteLine("The greatest number is {0}", greater);

            // Test Factorial
            bool ok;
            int  f;

            Console.WriteLine("Please input natural number for factorial calculation: ");
            x  = int.Parse(Console.ReadLine());
            ok = Utils.Factorial(x, out f);
            if (ok)
            {
                Console.WriteLine("Factorial of " + x + " = {0}", f);
            }
            else
            {
                Console.WriteLine("Overflow error");
            }
        }
Beispiel #9
0
        public static void Main()
        {
            int  f;
            bool ok;
            int  x;



            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());


            ok = Utils.Factorial(x, out f);


            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            int x;
            int y;

            Console.WriteLine("Введите первое число:");
            x = int.Parse(Console.ReadLine());
            Console.WriteLine("Введите второе число:");
            y = int.Parse(Console.ReadLine());

            int greater = Utils.Greater(x, y);

            Console.WriteLine("Большим из чисел {0} и {1} является {2} ", x, y, greater);

            Utils.Swap(ref x, ref y);
            Console.WriteLine("До swap: \t" + x + " " + y);
            Utils.Swap(ref x, ref y);
            Console.WriteLine("После swap: \t" + x + " " + y);

            int  f;
            bool ok;

            Console.WriteLine("Number for factorial:");
            x = int.Parse(Console.ReadLine());


            // Test the factorial function
            ok = Utils.Factorial(x, out f);
            // Output factorial results
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }


            char anwer;

            Console.WriteLine("Равностороний - 1, Обычный - 2");
            anwer = Char.Parse(Console.ReadLine());

            if (anwer == '1')
            {
                Console.WriteLine("Введите значение стороны:");
                double a    = Double.Parse(Console.ReadLine());
                double area = Operation.area(a);
                Console.WriteLine("Площадь треугольника: " + area);
            }
            else
            {
                Console.WriteLine("Введите значение первой стороны:");
                double a = Double.Parse(Console.ReadLine());
                Console.WriteLine("Введите значение второй стороны:");
                double b = Double.Parse(Console.ReadLine());
                Console.WriteLine("Введите значение третей стороны:");
                double c = Double.Parse(Console.ReadLine());
                try
                {
                    double area = Operation.area(a, b, c);
                    Console.WriteLine("Площадь треугольника: " + area);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Неверные значения сторон");
                }
            }
            double ca, cb, cc, x1, x2;

            Console.WriteLine("Введите коэффициента a: ");
            ca = Double.Parse(Console.ReadLine());
            Console.WriteLine("Введите коэффициента a: ");
            cb = Double.Parse(Console.ReadLine());
            Console.WriteLine("Введите коэффициента a: ");
            cc = Double.Parse(Console.ReadLine());
            int ans = Operation.squareRoot(ca, cb, cc, out x1, out x2);
            {
                if (ans == 1)
                {
                    Console.WriteLine("Корни уравнения с коэффициентами a = {0}, b = {1}, c = {2}\n" +
                                      " равны x1 = {3}, x2 = {4}.", ca, cb, cc, x1, x2);
                }
                else if (ans == 0)
                {
                    Console.WriteLine("Корнень уравнения с коэффициентами a = {0}, b = {1}, c = {2}\n" +
                                      " равен x1 = x2 = {3}.", ca, cb, cc, x1);
                }
                else
                {
                    Console.WriteLine("Корней уравнения с коэффициентами a = {0}, b = {1}, c = {2} нет", ca, cb, cc);
                }
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            /* initializing variables */
            int x;
            int y;

            /* getting users data */
            Console.WriteLine("Enter first number: ");  // asking preson to enter first value
            x = int.Parse(Console.ReadLine());          // assigning first value to int variable
            Console.WriteLine("Enter second number: "); // asking preson to enter second value
            y = int.Parse(Console.ReadLine());          // assigning second value to int variable

            /* getting maximum value out of two entered */
            int greater = Utils.Greater(x, y);

            /* printing maximum of two numbers */
            Console.WriteLine("Greater number of {0} and {1} is {2} ", x, y, greater);

            /* printing old variables information */
            Console.WriteLine("Before swap: \t" + x + " " + y);

            /* swapping x and y */
            Utils.Swap(ref x, ref y);

            /* printing new variables information */
            Console.WriteLine("After swap: \t" + x + " " + y);

            /* initializing variables */
            int  f;  // factorial variable
            bool ok; // state variable

            /* getting users data */
            Console.WriteLine("Number for factorial: "); // asking to enter number for factorail
            x = int.Parse(Console.ReadLine());

            /* evaluating factorial */
            ok = Utils.Factorial(x, out f);

            /* checking if evaluating factorial was successful */
            if (ok)
            {
                Console.WriteLine("Factorial(" + x + ") = " + f);
            }
            else
            {
                Console.WriteLine("Cannot compute this factorial");
            }

            /* getting users data */
            Console.WriteLine("Enter type of triangle\n1 - equal sides\n2 - non equal sides"); // asking person to enter type of the triangle
            int choise = int.Parse(Console.ReadLine());                                        // assigning choise to int variable

            /* declarating square variable */
            double square;

            /* checking for type of trianlge */
            if (choise == 1)
            {
                /* getting users data */
                Console.Write("Enter side of the triangle: ");  // asking to enter side of triangle
                double side = double.Parse(Console.ReadLine()); // assigning side to double variable

                /* evaluating square of the triangle */
                square = Utils.Square(side);
            }
            else
            {
                /* getting users data */
                Console.Write("Enter len of first side: ");       // asking persin to enter first side
                double side_1 = double.Parse(Console.ReadLine()); // assigning first side length to double variable
                Console.Write("Enter len of second side: ");      // asking persin to enter second side
                double side_2 = double.Parse(Console.ReadLine()); // assigning second side length to double variable
                Console.Write("Enter len of third side: ");       // asking persin to enter third side
                double side_3 = double.Parse(Console.ReadLine()); // assigning third side length to double variable

                /* evaluating square of the triangle */
                square = Utils.Square(side_1, side_2, side_3);
            }

            /* printing square */
            Console.WriteLine("Squre is {0}", square);

            /* getting users data */
            Console.Write("Enter a coefficient: ");          // asking person to enter a coefficient
            double a = Convert.ToDouble(Console.ReadLine()); // assigning a to double variable

            Console.Write("Enter b coefficient: ");          // asking person to enter b coefficient
            double b = Convert.ToDouble(Console.ReadLine()); // assigning b to double variable

            Console.Write("Enter c coefficient: ");          // asking person to enter c coefficient
            double c = Convert.ToDouble(Console.ReadLine()); // assigning c to double variable

            /* initializing roots variables */
            double x1 = 0; // first root variable
            double x2 = 0; // second root variable
            int    state;  // initializing state of operation

            /* counting roots x1, x2 using Utils built in method */
            state = Utils.Roots(a, b, c, ref x1, ref x2);

            /* checking operating state */
            if (state == -1)
            {
                Console.WriteLine($"Корней уравнения с коэффициентами a = {a}, " +
                                  $"b = {b}, c = {c} нет");
            }
            else if (state == 0)
            {
                Console.WriteLine($"Корень уравнения с коэффициентами a = {a}, " +
                                  $"b = {b}, c = {c} один x1 = x2 = {x1}");
            }
            else
            {
                Console.WriteLine($"Корни уравнения с коэффициентами a = {a}, " +
                                  $"b = {b}, c = {c} равны x1 = {x1}, x2 = {x2}");
            }

            /* to keep console awake */
            Console.ReadLine();
        }