Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace QuadraticEquation
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("A = ");
- int a = int.Parse(Console.ReadLine());
- Console.Write("B = ");
- int b = int.Parse(Console.ReadLine());
- Console.Write("C = ");
- int c = int.Parse(Console.ReadLine());
- double d = b * b - 4 * a * c;
- double x1, x2;
- if (a == 0)
- {
- if (b == 0 && c == 0)
- {
- Console.WriteLine("All real numbers are solutions!");
- }
- else if (b == 0 && c != 0)
- {
- Console.WriteLine("There aren't real roots!");
- }
- else
- {
- x1 = x2 = -c / b;
- Console.Write("x = ");
- Console.WriteLine(x1);
- }
- }
- else
- {
- if (d < 0)
- {
- Console.WriteLine("There aren't real roots!");
- }
- else if (d == 0)
- {
- x1 = x2 = -b / 2 * a;
- Console.Write("x1 = x2 = ");
- Console.WriteLine(x1);
- }
- else
- {
- x1 = (-b + Math.Sqrt(d)) / (2 * a);
- x2 = (-b - Math.Sqrt(d)) / (2 * a);
- Console.Write("x1 = ");
- Console.WriteLine(x1);
- Console.Write("x2 = ");
- Console.WriteLine(x2);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement