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