C# 数组写成绩的总分与平均分

定义一个数组,长度不限,要求用户输入成绩并存储
输出总成绩、平均成绩
进行异常处理

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();
        }
    }
}

小剧场:我相信我将能看到彩虹的美丽。

英文版:I believe I will be able to see the beauty of the rainbow.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章