[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace average
{
class Program
{
static void Main(string[] args)
{
int source, count, sum;
count = 0;
sum = 0;
Console.WriteLine("输入数字(stop退出):");
while (true)
{
try
{
string str = Console.ReadLine();
if (str.Equals("stop"))
{
break;
}
else
{
source = int.Parse(str);
sum += source;
count += 1;
}
}
catch (Exception ex)
{
}
}
Console.WriteLine("avg = {0}",sum / count);
Console.ReadLine();
}
}
}
|