<pre class="csharp" name="code"><pre class="html" name="code"><pre class="csharp" name="code">using System;
public class Test
{
public static void Main()
{
// your code goes here
double a,b,c; //边长
Console.WriteLine("请输入边长a");
a=Convert.ToDouble(Console. ReadLine());
Console.WriteLine("请输入边长b");
b=Convert.ToDouble(Console. ReadLine());
Console.WriteLine("请输入边长c");
c=Convert.ToDouble(Console. ReadLine());
if (a<=0||b<=0||c<=0) //防止输入错误数值
{
Console.WriteLine("输入错误");
Console.Read();
}
if (a + b > c && a + c > b && b + c > a) //判断输入数值能否成立三角形
{
if (a == b && b == c)
{ Console.WriteLine("是等边三角形");
Console.Read(); }
else if (a == b || b == c || a == c)
{ Console.WriteLine("是等腰三角形");
Console.Read(); }
else if ((a * a) + (b * b) == (c * c) || (a * a) + (c * c) == (b * b) || (b * b) + (c * c) == (a * a))
{
{
Console.WriteLine("是直角三角形");
Console.Read();
}
if (a == b || b == c || a == c)
{
Console.WriteLine("是等腰直角三角形");
Console.Read();
}
}
else
{
Console.WriteLine("是任意三角形");
Console.Read();
}
}
else
{
Console.WriteLine("输入的三边不能组成三角形");
Console.Read();
}
}
}
作业 :判断三角形是否成立
最新推荐文章于 2024-04-08 10:46:16 发布