
Ralph W. answered 06/08/21
Crafting Code with Clarity: A Guided Journey Through C#
c = equations[loop].Coefficients;
double temp0 = (4 * c[0] * c[2]);
double temp1 = c[1] * c[1];
double temp2 = temp1 - temp0;
double temp3 = 0;
double temp4 = 0;
double temp5 = 0;
double temp6 = 0;
double temp7 = 0;
double temp8 = 0;
imaginaryValue = false;
if (temp2 > 0)
{
temp3 = (2 * c[0]);
temp4 = Math.Sqrt(temp2);
temp5 = -c[1];
x[0] = ((temp5 + temp4) / temp3);
}
else if (temp2 == 0)
{
temp3 = (2 * c[0]);
temp4 = 0;
temp5 = -c[1];
x[0] = ((temp5 + temp4) / temp3);
}
else
{
temp3 = (2 * c[0]);
temp4 = Math.Sqrt(Math.Abs(temp2));
temp5 = -c[1];
x[0] = ((temp5) / temp3);
imaginaryValue = true;
}
Console.WriteLine("x = (-b -/+ sqrt((b^2-4ac)))/2a");
Console.WriteLine("4ac = " + temp0);
Console.WriteLine("b^2 = " + temp1);
Console.WriteLine("b^2 - 4ac = " + temp2);
Console.WriteLine("2a = " + temp3);
Console.WriteLine("sqrt(b^2-4ac) = " + temp4);
Console.WriteLine("-b = " + temp5);
Console.WriteLine("(-b + sqrt((b^2-4ac))/2a = " + x[0]);
temp6 = c[0] * x[0] * x[0];
temp7 = c[1] * x[0];
temp8 = c[2];
Console.WriteLine("ax^2 = " + temp6);
Console.WriteLine("bx = " + temp7);
Console.WriteLine("c = " + temp8);
y[0] = temp6 + temp7 + temp8;
if (imaginaryValue)
{
Console.WriteLine("y = " + y[0]);
Console.WriteLine("Found: [" + x[0] + "+i, " + y[0] + "]");
}
else
{
Console.WriteLine("y = " + y[0]);
Console.WriteLine("Found: [" + x[0] + ", " + y[0] + "]");
}