C#語言,求成績平均數。


輸入大於五的人數成績,去掉兩個最高分,和兩個最低分,求其平均數。
Console.Write("請輸入人數");

int renshu = int.Parse(Console.ReadLine());
int[] chengji = new int[renshu];


if (renshu >= 5)
{
for (int h = 1; h <= renshu; h++)
{
Console.Write("請輸入第" + h + "個人成績");       這一步是顯示,請輸入第一個人的成績請輸入第二個人的成績請輸入第三個人的成績請輸入第四個人的成績請輸入第五個人的成績


chengji[h - 1] = int.Parse(Console.ReadLine());     這一步是顯示,請輸入第一個人的成績——,請輸入第二個人的成績——,請輸入第三個人的成績——,請輸入第四個人的成績——,請輸入第五個人的成績——
}


for (int i = 1; i < renshu; i++)       冒泡排序,成績由大到小排列。
{

for (int j = 1; j < renshu - 1; j++)
{
if (chengji[i] < chengji[j + 1])
{
int zhong = 0;         中間值
zhong = chengji[i];
chengji[i] = chengji[j + 1];
chengji[j + 1] = zhong;
}
}
}
int he = 0;
for (int i = 0; i <= (renshu - 1); i++)       算出總成績
{
he = he + chengji[i];

}
double pj = (he - chengji[0] - chengji[1] - chengji[renshu - 2] - chengji[renshu - 1]) / (renshu - 4);
Console.WriteLine("去掉最高分{0}{1},去掉最低分{2}{3},最后平均成績是:{4}", chengji[0], chengji[1], chengji[renshu - 2], chengji[renshu - 1], pj);
}
else {
Console.WriteLine("輸入的人數要大於五啊");
}

 

Console.ReadLine();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM