Skip to content

Instantly share code, notes, and snippets.

@boyanov83
Created October 18, 2014 15:15
Show Gist options
  • Save boyanov83/28e6fd200a143d166fc4 to your computer and use it in GitHub Desktop.
Save boyanov83/28e6fd200a143d166fc4 to your computer and use it in GitHub Desktop.
using System;
class Program
{
static void Main()
{
double a, b, c, x1, x2;
a = double.Parse(Console.ReadLine());
b = double.Parse(Console.ReadLine());
c = double.Parse(Console.ReadLine());
double insideSquareRoot = (b * b) - 4 * a * c;
double t = (-0.5 * (b + Math.Sign(b) * Math.Sqrt(insideSquareRoot)));
if (insideSquareRoot < 0)
{
Console.WriteLine("no real roots");
}
else
{
x1 = t / a;
x2 = c / t;
if(x1==x2)
{
Console.WriteLine("x1=x2="+ x1);
}
else
{
Console.WriteLine("x1="+x1+"; x2="+x2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment