Advertisement
StoneHaos

nastya

Nov 14th, 2020
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace main {
  4.     class Program {
  5.         public static void Main(string [] args) {
  6.             Console.Write("Значение a=");
  7.             double a = double.Parse(Console.ReadLine());
  8.             Console.Write("Значение b=");
  9.             double b = double.Parse(Console.ReadLine());
  10.             Console.Write("Значение c=");
  11.             double c = double.Parse(Console.ReadLine());
  12.             double x1, x2;
  13.             if (answ(a, b, c, out x1, out x2)) {
  14.                 if (x1 == x2)
  15.                     Console.WriteLine("1 корень:\nx1 = {0}", x1);
  16.                 else
  17.                     Console.WriteLine("2 корня:\nx1 = {0}\nx2 = {1}", x1, x2);
  18.  
  19.             }
  20.             else
  21.                 Console.WriteLine("Коней нет");
  22.         }
  23.  
  24.         static bool answ(double a, double b, double c, out double x1, out double x2) {
  25.             double d = b * b - 4 * a * c;
  26.             if (d < 0 || a == 0) {
  27.                 x1 = 0;
  28.                 x2 = 0;
  29.                 return false;
  30.             }
  31.             x1 = (-b + Math.Sqrt(d)) / (2 * a);
  32.             x2 = (-b - Math.Sqrt(d)) / (2 * a);
  33.             return true;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement