Function--The case of more than one return value (solution of a two-second equation)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.