当前位置:首页 > Windows程序 > 正文

每日一题(一)

2024-03-31 Windows程序

进击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;
}

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/43091.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494595访问次数
  • 建站天数
  • 友情链接