定义一个数组,长度不限,要求用户输入成绩并存储
输出总成绩、平均成绩
进行异常处理
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();
}
}
}