计算五位学生的平均分(用数组)

//计算五位学生的平均分,五位学生的成绩分别为:60 80 90 70 85

try { int[] scores = new int[5];//成绩数组

int sum = 0;//成绩总和

 Console.WriteLine("请输入5位学员的成绩:");

for (int i = 0; i < scores.Length; i++)

{

 scores[i] = Convert.ToInt32(Console.ReadLine());

sum = sum + scores[i];//成绩累加

 }

 Console.WriteLine("平均分是:"+(double)sum/scores.Length);

}

 catch


{ Console.WriteLine("输入格式错误");

 }

 Console.ReadKey();

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • using System; using System.Collections.Generic; using Sys...
    一只皮皮橙阅读 193评论 0 0
  • 知识点: 注:int类型默认32位有大小范围 且第一位为符号位 0 为正 1 为负 8.4作业 A:1、风力预警系...
    cGunsNRoses阅读 1,122评论 0 0
  • using System; using System.Collections.Generic; using Sys...
    一只皮皮橙阅读 178评论 0 0
  • namespace ConsoleApplication1 { class Program { static vo...
    鲸落_79f1阅读 154评论 0 0
  • /** * 值类型演示 * 前面介绍的基本数据类型都是值类型,到目前为止,我们学过的引用类型只有字符串和数组, *...
    29e0c7456d81阅读 141评论 0 0