码迷,mamicode.com
首页 > Windows程序 > 详细

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

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

标签:函数返回值   oid   成绩   返回值   c#   int   get   str   指点   

进击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#新手_每日一题(一)

标签:函数返回值   oid   成绩   返回值   c#   int   get   str   指点   

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

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