Console.WriteLine("请输入数字的个数");
int sum = 0;
bool b = true;
try
{
int number = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < number; i++)
{
Console.WriteLine("请输入第{0}个数", i + 1);
try
{
int s = Convert.ToInt32(Console.ReadLine());
sum += s * s;
}
catch
{
Console.WriteLine("输入有误,程序退出");
b = false;
}
}
}
catch
{
Console.WriteLine("输入有误,程序退出");
b = false;
}
if(b)
{
Console.WriteLine("这几个数的平方和是{0}", sum);
}
Console.ReadKey(); |