C#循环接收学员成绩并输出总分和平均分
程序员文章站
2022-03-22 23:50:44
using System;using System.Collections.Generic;using System.Text;namespace KnowledgePoint{ class _14_Ex_While { static void Main() { Console.Write("请输入班级人数:"); int nop = Convert.ToInt32(Console.ReadLine()...
using System;
using System.Collections.Generic;
using System.Text;
namespace KnowledgePoint
{
class _14_Ex_While
{
static void Main()
{
Console.Write("请输入班级人数:");
int nop = Convert.ToInt32(Console.ReadLine());
double sumScore = 0.0; // 总成绩
int i = 1; // 循环变量
while (i <= nop)
{
Console.Write("\n请输入第 {0} 个学员的成绩:", i);
int score = Convert.ToInt32(Console.ReadLine());
sumScore += score; // 循环接收每次输入的学员成绩
i++; // 循环变量自增
}
Console.Write("\n提示:班级人数{0},总分{1},平均分{2}", nop, sumScore, (sumScore / nop));
Console.ReadKey();
}
}
}
本文地址:https://blog.csdn.net/qq_44965393/article/details/107295613