Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class QuadraticEquation
- {
- static void Main()
- { //ax*x + bx + c = 0
- Console.WriteLine("Enter a, b, c for ax*x + bx + c = 0");
- double a = double.Parse(Console.ReadLine());
- double b = double.Parse(Console.ReadLine());
- double c = double.Parse(Console.ReadLine());
- double x1, x2;
- //d = discriminant
- double d = (b * b) - (4 * a * c);
- if (d == 0)
- {
- x1 = x2 = (-b) / 2 * a;
- Console.WriteLine("x1 = x2 = {0:0.000}", x1);
- }
- else if (d > 0)
- {
- x1 = (-b) + Math.Sqrt(d) / 2 * a;
- x2 = (-b) - Math.Sqrt(d) / 2 * a;
- Console.WriteLine("x1 = {0:0.000}, x2 = {1:0.000}", x1, x2);
- }
- else
- {
- Console.WriteLine("No real roots!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement