2013年计算机二级C语言上机题库一_第3页

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年2月26日
 编程题
  M个人的成绩存放在score数组中,请编写函数fun,它的功能是:返回低于平均分的认输,并将低于平均分的分数放在below所指的数组中。
  例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的认输应该是4,below中的数据应我10、20、30、40。
  注意:部分源程序给出如下。
  请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
  试题程序:
  #include
  #include
  #include  
  int fun(int score[],int m, int below[])
  {  
  }
  main()
  {
  int i,n,below[9];
  int score[9]={10,20,30,40,50,60,70,80,90};
  FILE *out;
  n=fun(score,9,below);
  printf("\nBelow the average score are :");
  out=fopen("out.dat", "w");
  for(i=0;i  {
   printf("%d ",below[i]);
   fprintf(out, "%d\n", below[i]);
  }
  fclose(out);
  }
  答案是:
  int fun(int score[], int m, int below[])
  {
   int I, k=0,aver=0;
  for(i=0;i  aver+=score[i];
  aver/=m;
  for(i=0;i  if(score[i]  {
  below[k]=score[i];
   k++;
  }
  return k;
  }
首页 1 2 3 尾页

相关文章