Namespace two-time equation function solution
{
Class Program
{
static void Main (string[] args)
{
while (true)
{
Console.WriteLine ("Please set the relevant parameters for the unary two-time equation ax²+bx+c:");
Console.WriteLine ("Please enter A:");
int a = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter B:");
int b = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter C:");
int c = Convert.ToInt32 (Console.ReadLine ());
Double x1=0;//Define two variables to receive out X1 and x2
Double x2=0;
String s= new program (). Solve (a,b,c,out x1,out x2);//Call function solve input parameter a,b,c used for function operation and parameter except return value out X1 and out X2
Console.WriteLine (s);
Console.WriteLine ("First root:" +x1);
Console.WriteLine ("Second root:" +x2);
Console.ReadLine ();
}
}
<summary>
Solution equation
</summary>
<param name= "a" ></param>
<param name= "B" ></param>
<param name= "C" ></param>
<returns></returns>
public string Solve (int a, int b, int c,out double x1,out double x2)//Define a function to solve the equation
{
string S;
int x=b*b-4*a*c;
if (A > 0 | | A < 0)
{
if (x>0)
{
s = "The equation has two unequal roots";
}
else if (x==0)
{
s = "The equation has two equal roots";
}
Else
{
s = "The equation has no roots";
}
}
Else
{
s = "The equation has no roots";
}
X1 = (-B + math.sqrt (x))/(2 * a);//math.sqrt (); square root
x2 = (-b-math.sqrt (x))/(2 * a);
return s;//Returns a string of type S
}
}
}
Function--The case of more than one return value (solution of a two-second equation)