定義一個數組,長度不限,要求用戶輸入成績並存儲
輸出總成績、平均成績
進行異常處理
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSbaseDemo2
{
class Program
{
static void Main(string[] args)
{
try
{
int[] arr = new int[5];
int ans = 0;
Console.WriteLine("請輸入五位同學的成績:");
for (int i = 0; i < arr.Length; i++)
{
arr[i] = int.Parse(Console.ReadLine());
ans += arr[i];
}
Console.WriteLine("五位同學的總成績爲:"+ans);
Console.WriteLine("五位同學的平均成績:"+ans/5);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
Console.ReadKey();
}
}
}