C#从键盘连续输入N 个正整数求其平均值

c#.NET,控制台应用程序

static void OperateNum()
{
Console.WriteLine("请输入一个数字:");
Int32 num = Convert.ToInt32(Console.ReadLine());
Int32 i = 0;
Int32 tot = 0;
while (num > 0)
{
Console.WriteLine("请输入下一个数字:");
tot = tot + num;
i++;
num = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("总共输入数字{0}个,平均值为{1}.",i,Convert.ToSingle(tot)/i);
return;
}追问

我运行了,有错,不行

追答

没错阿,我在电脑上运行了才发上来的.我用的是VS2010

追问

追答

我晕,你把主程序入口都删除了,肯定产生错误啊
static void Main(string[] args)
{
OperateNum();
}

追问

怎么输出结果

温馨提示:答案为网友推荐,仅供参考
相似回答