Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace l1
- {
- class Program
- {
- public static double a;
- public static double b;
- public static double c;
- public static double x1;
- public static double x2;
- public static void InputABC()
- {
- Console.Write("Введите a: ");
- a = double.Parse(Console.ReadLine());
- Console.Write("Введите b: ");
- b = double.Parse(Console.ReadLine());
- Console.Write("Введите c: ");
- c = double.Parse(Console.ReadLine());
- }
- static void Main(string[] args)
- {
- //Найти корни квадратного уравнения a*x^2+b*x+c=0
- // == - проверяет равенство
- // & - логическое И
- // | - логическое ИЛИ
- InputABC();
- double d = Math.Pow(b, 2) - 4 * a * c;
- switch (d > 0)
- {
- case true:
- x1 = (-b + Math.Sqrt(d)) / 2 * a;
- x2 = (-b - Math.Sqrt(d)) / 2 * a;
- Console.WriteLine($"Корни уравнения: {x1} и {x2}");
- break;
- case false:
- if(d==0)
- {
- x1 = (-b + Math.Sqrt(d)) / 2 * a;
- Console.WriteLine($"Корень уравнения: {x1}");
- }
- else
- Console.WriteLine("Корней нет");
- break;
- default:
- Console.WriteLine(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement