1.求解一元二次方程
Console.WriteLine("求解一元二次方程:a*x*x+b*x+c=0");
Console.Write("请输入 a=");
double a = double.Parse(Console.ReadLine());
Console.Write("请输入 b=");
double b = double.Parse(Console.ReadLine());
Console.Write("请输入 c=");
double c = double.Parse(Console.ReadLine());
double delte = b * b - 4 * a * c;
if (a == 0)
{
Console.WriteLine("这是不是一个一元二次方程。");
}
else
{
Console.WriteLine("这是一个一元二次方程。");
if (delte > 0)
{
Console.WriteLine("有两个实数根,分别为:");
double x1 = (-b + (delte)) / (2 * a);
double x2 = (-b - (delte)) / (2 * a);
Console.Write(x1);
Console.Write(x2);
}
else if (delte == 0)
{
string s;
Console.WriteLine("有两个相同实数根,为:");
double x1 = (-b + (delte)) / (2 * a);
s =x1.ToString() ;
Console.Write("x1=x2="+s );
}
else if (delte < 0)
{
Console.WriteLine("该方程没有实根。");
}
}
Console.ReadLine();
2.征兵
Console.WriteLine("请输入您的性别:");
string z = Console.ReadLine();
if(z=="男")
{
Console .Write ("请输入您的年龄:");
string s=Console .ReadLine ();
int age = int.Parse(s);
if (age >= 18 && age < 60)
{
Console.WriteLine("年龄可以,抓取当兵!");
}
else if (age < 18&&age >0)
{
Console.WriteLine("年龄太小,回家吃奶去吧!!");
}
else if (age >= 60 && age <= 100)
{
Console.WriteLine("年龄太大,回家看孩子去吧!!");
}
else if (age > 100 && age < 150)
{
Console.WriteLine("老人家回家享福去吧!");
}
else if (age < 0 && age > 150)
{
Console.WriteLine("请核实年龄!");
}
else
{
Console.WriteLine("请核实年龄!");
}
#endregion
}
else if (z == "女")
{
Console.WriteLine("回家生娃去!");
}
else
{
Console.WriteLine("请核对您的性别!");
}
Console.ReadLine();