Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class QuadraticEquation
- {
- static void Main()
- {
- Console.Write("Enter a: ");
- int a = int.Parse(Console.ReadLine());
- Console.Write("Enter b: ");
- int b = int.Parse(Console.ReadLine());
- Console.Write("Enter c: ");
- int c = int.Parse(Console.ReadLine());
- double d = (b * b) - (4 * a * c);
- if (d >= 0)
- {
- if (d == 0)
- {
- Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has one root:", a, b, c);
- Console.WriteLine("x= {0}", (-b/(2*a)));
- }
- else
- {
- Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has the following roots:", a, b, c);
- Console.WriteLine("x1= {0}", ((-b+(Math.Sqrt(d)))/(2*a)));
- Console.WriteLine("x2= {0}", ((-b-(Math.Sqrt(d)))/(2*a)));
- }
- }
- else
- {
- Console.WriteLine("The quadratic equation with coefficients a={0}, b={1} and c={2} has NO roots:", a, b, c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement