2018-11-08(班级平均分+总成绩 while)
2018-11-08 本文已影响0人
Tn299
题目
输入班级人数,然后依次输入学员成绩,计算班级学员的平均成绩和总成绩
代码
static void Main(string[] args)
{ /**
* 输入班级人数,然后依次输入学员成绩,计算班级学员的平均成绩和总成绩
* */
Console.WriteLine("请输入班级人数");
string strnum = Console.ReadLine();
int num = Convert.ToInt32(strnum);
int i = 0; //学员人数
int sum = 0; //学员总成绩
while (i < num)
{
Console.WriteLine("输入学员成绩");
string strcj = Console.ReadLine();
int cj = Convert.ToInt32(strcj);
sum += cj;
i++;
}
int pjcj = sum / i;
Console.WriteLine("班级学员总成绩为{0},平均成绩为{1}",sum,pjcj);
Console.ReadKey();
效果图
