码迷,mamicode.com
首页 > Web开发 > 详细

.Net学习笔记----2015-07-10(基础复习和练习07)

时间:2015-07-10 02:05:10      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

为教师编写一个程序,该程序使用一个数组存储30个学生的考试成绩,并给各个数组元素指定一个1-100的随机值,然后计算平均成绩。

        static void Main(string[] args)
        {
            int[] score = new int[30];

            Random r = new Random();
            //int rNumber = r.Next(1, 101);
            //double sum = 0.00;
            //for (int i = 0; i < score.Length; i++)
            //{
            //    score[i] = r.Next(1, 101);
            //    Console.WriteLine(score[i]);
            //    //sum += score[i];
            //}
            
            
            Console.Write(Math.Round(AvgScore(score),2));
            Console.ReadKey();
        }

        static double AvgScore(int[] score)
        {
            Random r = new Random();
            
            double sum = 0.00;
            for (int i = 0; i < score.Length; i++)
            {
                score[i] = r.Next(1, 101);
                sum += score[i];
            }
            return sum / score.Length;
        }

 

.Net学习笔记----2015-07-10(基础复习和练习07)

标签:

原文地址:http://www.cnblogs.com/mikie/p/4634615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!