发布网友 发布时间:2024-10-24 01:19
共1个回答
热心网友 时间:2024-10-28 05:05
class Program
{
static void Main(string[] args)
{
string ins = "";
string[] sparr;
double[] parr = new double[4];
do
{
Console.Write("输入一组(2个点坐标数据,输入end退出):");
ins = Console.ReadLine();
sparr = ins.Trim().Replace(" "," ").Split(' ');
if (ins == "end")
{
break;
}else if (sparr.Length < 4)
{
Console.WriteLine("输入错误!");
}else
{
for (int i = 0; i < 4; ++i)
{
parr[i] = int.Parse(sparr[i]);
}
Console.WriteLine(" 两点距离:{0}", dis(parr[0], parr[1], parr[2], parr[3]));
}
Console.WriteLine("----------------------------------------------");
} while (true);
Console.Write("按下回车键程序退出...");
Console.Read();
}
static double dis(double x1, double y1, double x2, double y2)
{
double dx, dy;
dx = x2 - x1;
dy = y2 - y1;
return Math.Sqrt(dx * dx + dy * dy);
}
}
需要完善对输入合法性的判断