Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace main {
- class Program {
- public static void Main(string [] args) {
- Console.Write("Значение a=");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Значение b=");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Значение c=");
- double c = double.Parse(Console.ReadLine());
- double x1, x2;
- if (answ(a, b, c, out x1, out x2)) {
- if (x1 == x2)
- Console.WriteLine("1 корень:\nx1 = {0}", x1);
- else
- Console.WriteLine("2 корня:\nx1 = {0}\nx2 = {1}", x1, x2);
- }
- else
- Console.WriteLine("Коней нет");
- }
- static bool answ(double a, double b, double c, out double x1, out double x2) {
- double d = b * b - 4 * a * c;
- if (d < 0 || a == 0) {
- x1 = 0;
- x2 = 0;
- return false;
- }
- x1 = (-b + Math.Sqrt(d)) / (2 * a);
- x2 = (-b - Math.Sqrt(d)) / (2 * a);
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement