Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Write a program that reads the coefficients a, b and c of a quadratic equation ax2 + bx + c = 0 and solves it (prdoubles its real roots).
- class QuadraticEquation
- {
- static void Main()
- {
- Console.Write("Enter value for 'a': ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Enter value for 'b': ");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Enter value for 'c': ");
- double c = double.Parse(Console.ReadLine());
- double D = (b * b) - (4 * a * c);
- if (D < 0)
- {
- Console.WriteLine("no real roots");
- }
- else
- {
- if (D == 0)
- {
- double x = -b /( 2 * a);
- Console.WriteLine("x1=x2= {0}", x);
- }
- else
- {
- double x1 = ((-b) + Math.Sqrt(D)) / (2 * a);
- double x2 = ((-b) - Math.Sqrt(D)) / (2 * a);
- Console.WriteLine(" x1={0}; x2={1}", x1, x2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement