Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class QuadraticEquation
- {
- static void Main()
- {
- Console.WriteLine("Please enter \"a\":"); // takes the value of the coefficients
- double a = double.Parse(Console.ReadLine());
- Console.WriteLine("Please enter \"b\":");
- double b = double.Parse(Console.ReadLine());
- Console.WriteLine("Please enter\"c\":");
- double c = double.Parse(Console.ReadLine());
- double D = Math.Pow(b, 2) - 4 * a * c; // Formula for D
- if (D < 0) // gives you result if D is smaller than 0
- {
- Console.WriteLine("No real roots");
- }
- else if (D == 0) // gives you result if D is equal to 0
- {
- double x3 = (-b) / (2 * a);
- Console.WriteLine("x1=x2= {0}", x3);
- }
- else
- {
- double x1 = ((-b) - Math.Sqrt(D)) / (2 * a); // for all other cases this will be your equasion
- Console.WriteLine("Root x1 is:{0}", x1);
- double x2 = ((-b) + Math.Sqrt(D)) / (2 * a);
- Console.WriteLine("Root x2 is:{0}", x2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement