Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Discriminant
- {
- public static void Main(String[] args)
- {
- Console.Write("Введите значение a: ");
- double a = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите значение b: ");
- double b = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите значение c: ");
- double c = Convert.ToDouble(Console.ReadLine());
- if (a == 0 && b == 0 && c == 0 || a == 0 && b == 0 || b == 0 && c == 0 || a == 0 && c == 0)
- {
- Calc.error();
- }
- else if (a == 0)
- {
- Calc.noA(b, c);
- }
- else if (b == 0)
- {
- Calc.noB(a, c);
- }
- else if (c == 0)
- {
- Calc.noC(a, b);
- }
- else
- {
- Calc.all(a, b, c);
- }
- }
- }
- public class Calc
- {
- public static void error()
- {
- Console.WriteLine("\nОшибка");
- }
- public static void noA(double b, double c)
- {
- double temp1 = c / b;
- double x = temp1 * -1;
- Console.WriteLine($"\nЗначение x = {x}");
- }
- public static void noB(double a, double c)
- {
- double temp1 = c * -1;
- double temp2 = temp1 / a;
- double temp3 = Math.Sqrt(temp2);
- double x1 = temp3;
- double x2 = temp3 * -1;
- Console.WriteLine($"\nЗначение x1 = {x1} x2 = {x2}");
- }
- public static void noC(double a, double b)
- {
- double x;
- x = b / a;
- x = x * -1;
- Console.WriteLine($"\nЗначение x = 0 или {x}");
- }
- public static void all(double a, double b, double c)
- {
- double temp1 = b * b;
- double temp2 = 4 * a * c;
- double temp3 = temp1 - temp2;
- Console.WriteLine($"\nДискриминант = {temp3}");
- if (temp3 < 0)
- {
- Console.WriteLine("Корней нет");
- }
- else
- {
- double temp4 = Math.Sqrt(temp3);
- temp1 = b * -1;
- temp2 = temp1;
- temp1 = temp1 - temp4;
- temp2 = temp2 + temp4;
- temp3 = a * 2;
- double x1 = temp1 / temp3;
- double x2 = temp2 / temp3;
- Console.WriteLine($"\nЗначение x1 = {x1} x2 = {x2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement