Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace l1
  7. {
  8.     class Program
  9.     {
  10.         public static double a;
  11.         public static double b;
  12.         public static double c;
  13.         public static double x1;
  14.         public static double x2;
  15.  
  16.         public static void InputABC()
  17.         {
  18.             Console.Write("Введите a: ");
  19.             a = double.Parse(Console.ReadLine());
  20.             Console.Write("Введите b: ");
  21.             b = double.Parse(Console.ReadLine());
  22.             Console.Write("Введите c: ");
  23.             c = double.Parse(Console.ReadLine());
  24.         }
  25.  
  26.         static void Main(string[] args)
  27.         {
  28.             //Найти корни квадратного уравнения a*x^2+b*x+c=0
  29.             // == - проверяет равенство
  30.             // & - логическое И
  31.             // | - логическое ИЛИ
  32.  
  33.             InputABC();
  34.             double d = Math.Pow(b, 2) - 4 * a * c;
  35.             switch (d > 0)
  36.             {
  37.                 case true:
  38.                     x1 = (-b + Math.Sqrt(d)) / 2 * a;
  39.                     x2 = (-b - Math.Sqrt(d)) / 2 * a;
  40.                     Console.WriteLine($"Корни уравнения: {x1} и {x2}");
  41.                     break;
  42.                 case false:
  43.                     if(d==0)
  44.                     {
  45.                         x1 = (-b + Math.Sqrt(d)) / 2 * a;
  46.                         Console.WriteLine($"Корень уравнения: {x1}");
  47.                     }
  48.                     else
  49.                         Console.WriteLine("Корней нет");
  50.                     break;
  51.                 default:
  52.                     Console.WriteLine(1);
  53.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement