首页 > Windows开发 > 详细

c#新手_每日一题(一)

时间:2017-04-10 21:34:35      阅读:160      评论:0      收藏:0      [点我收藏+]

进击c#的小白一枚,望大神指点。

每日一题
M 个人的成绩存放在 score 数组中,请编写函数 GetBelowScore(),它的 功能是:返回低于平均分的分数,并将低于平均分的分数放在 below 所指的数组中。  例如,当 score 数组中的数据为 10、20、30、40、50、60、 70、80、90 时,函数返回值应该是 4,below 中的数据应为10、20、30、40.

static void Main(string[] args)
{
  int[] score = { 10, 20, 30, 40, 50, 60, 70, 80, 90,100 };
  Console.WriteLine("\n"+GetBelowScore(score,score));
  Console.ReadLine();
}
static int GetBelowScore(int[] score,int[] below)
{
  int mun = 0;
  int x = 0;
  for (int i = 0; i < score.Length; i++)
  {
    mun += score[i];
  }
  int mean = mun / score.Length;
  for (int i = 0; i <score.Length; i++)
  {
    if (score[i] < mean)
      {
        below[x] = score[i];
        Console.Write(below[x] + " ");
        x++;
      }
  }
  return x;
}

 

c#新手_每日一题(一)

原文:http://www.cnblogs.com/lhhqq-114/p/6690777.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!