2018-11-08

#代碼

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

? ? class Program

? ? {

? ? ? ? static void Main(string[] args)

? ? ? ? {

? ? ? ? ? ? Console.WriteLine("請輸入班級人數");

? ? ? ? ? ? int count = Convert.ToInt32(Console.ReadLine());

? ? ? ? ? ? int i = 0;//聲明一個循環變量,記錄循環的次數

? ? ? ? ? ? int sum = 0;//定義總成績

? ? ? ? ? ? while (i < count)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? Console.WriteLine("請輸入第{0}個學員的成績", i + 1);

? ? ? ? ? ? ? ? try

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? int score = Convert.ToInt32(Console.ReadLine());

? ? ? ? ? ? ? ? ? ? //將每一個學員的成績累加到總成績中

? ? ? ? ? ? ? ? ? ? sum += score;

? ? ? ? ? ? ? ? ? ? i++;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? catch

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Console.WriteLine("輸入有誤,請重新輸入");

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? Console.WriteLine("{0}個人的班總成績是{1}平均成績是{2}", count, sum, sum / count);

? ? ? ? ? ? Console.ReadKey();

? ? ? ? }

? ? }

}

#效果


?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 2017/10/29 1.C#基礎語法: 矩陣類的實現 using System; using System.Co...
    文袁閱讀 549評論 0 0
  • 知識點: 注:int類型默認32位有大小范圍 且第一位為符號位 0 為正 1 為負 8.4作業 A:1、風力預警系...
    cGunsNRoses閱讀 1,122評論 0 0
  • On Mar 26, Chinese crude oil futures traded officiall...
    留子兒閱讀 170評論 0 0
  • 有的家長提出,你講的東西學校不考,我們是要來提分的。還有家長直接問,我們這一次想要月考成績考到班上前10名,你能不...
    靜水ww閱讀 649評論 7 15
  • 二十幾歲的年紀,即將走出校園,踏入社會,在這一路上好像漸漸迷失了自己的方向。 小學的時候,老師的喜歡,積極...
    二六十二閱讀 256評論 2 1