Advertisement
lll_Death_lll

C# Discriminant

Feb 3rd, 2023 (edited)
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. public class Discriminant
  2. {
  3.     public static void Main(String[] args)
  4.     {
  5.  
  6.         Console.Write("Введите значение a: ");
  7.         double a = Convert.ToDouble(Console.ReadLine());
  8.         Console.Write("Введите значение b: ");
  9.         double b = Convert.ToDouble(Console.ReadLine());
  10.         Console.Write("Введите значение c: ");
  11.         double c = Convert.ToDouble(Console.ReadLine());
  12.  
  13.         if (a == 0 && b == 0 && c == 0 || a == 0 && b == 0 || b == 0 && c == 0 || a == 0 && c == 0)
  14.         {
  15.             Calc.error();
  16.         }
  17.  
  18.         else if (a == 0)
  19.         {
  20.             Calc.noA(b, c);
  21.         }
  22.         else if (b == 0)
  23.         {
  24.             Calc.noB(a, c);
  25.         }
  26.  
  27.         else if (c == 0)
  28.         {
  29.             Calc.noC(a, b);
  30.         }
  31.  
  32.         else
  33.         {
  34.             Calc.all(a, b, c);
  35.         }
  36.  
  37.     }
  38. }
  39.  
  40. public class Calc
  41. {
  42.     public static void error()
  43.     {
  44.         Console.WriteLine("\nОшибка");
  45.     }
  46.  
  47.     public static void noA(double b, double c)
  48.     {
  49.  
  50.         double temp1 = c / b;
  51.         double x = temp1 * -1;
  52.         Console.WriteLine($"\nЗначение x = {x}");
  53.  
  54.     }
  55.  
  56.     public static void noB(double a, double c)
  57.     {
  58.  
  59.         double temp1 = c * -1;
  60.         double temp2 = temp1 / a;
  61.         double temp3 = Math.Sqrt(temp2);
  62.         double x1 = temp3;
  63.         double x2 = temp3 * -1;
  64.  
  65.         Console.WriteLine($"\nЗначение x1 = {x1} x2 = {x2}");
  66.     }
  67.  
  68.     public static void noC(double a, double b)
  69.     {
  70.  
  71.         double x;
  72.  
  73.         x = b / a;
  74.         x = x * -1;
  75.  
  76.         Console.WriteLine($"\nЗначение x = 0 или {x}");
  77.     }
  78.  
  79.     public static void all(double a, double b, double c)
  80.     {
  81.         double temp1 = b * b;
  82.         double temp2 = 4 * a * c;
  83.         double temp3 = temp1 - temp2;
  84.         Console.WriteLine($"\nДискриминант = {temp3}");
  85.         if (temp3 < 0)
  86.         {
  87.             Console.WriteLine("Корней нет");
  88.         }
  89.         else
  90.         {
  91.             double temp4 = Math.Sqrt(temp3);
  92.             temp1 = b * -1;
  93.             temp2 = temp1;
  94.             temp1 = temp1 - temp4;
  95.             temp2 = temp2 + temp4;
  96.             temp3 = a * 2;
  97.             double x1 = temp1 / temp3;
  98.             double x2 = temp2 / temp3;
  99.  
  100.             Console.WriteLine($"\nЗначение x1 = {x1} x2 = {x2}");
  101.         }
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement