m个人的成绩存放在score数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。 例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人

admin2016-12-06  41

问题 m个人的成绩存放在score数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。
    例如,当score数组中的数据为10、20、30、40、50、60、70、80、90时,函数返回的人数应该是4,below中的数据应为10、20、30、40。
    注意:部分源程序在文件PROG1.C中。
    请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
    试题程序:
1   #include<conio.h>
2   #include<stdio.h>
3   #include<string.h>
4   #include<stdlib.h>
5   int fun(int score[],int m,int below[])
6   {
7
8   }
9   void main()
10   {
11   FILE*wf;
12   int i,n,below[9];
13   int score[9]={10,2 0,30,40,50,60,70,80,90};
14   system(’’CLS’’);
15   n=fun(sCOEe,9,below);
16   printf(’’\nBelow the average score are:’’);
17    for(i=0 ; i18    printf(’’%d’’,below);
19   /*****************/
20   wf=fopen(’’out.dat’’,’’w’’);
21    for(i=0;i22    fprintf(wf,’’%d’’,below);
23    fclose(wf);
24   /*****************/
25  }

选项

答案1 int fun(int score[],int m,int be-low[]) 2 { 3 int i,j=0 ; 4 float av=0.0; 5 for(i=0 ; i
解析 要计算低于平均分的人数,首先应该求出平均分,然后通过for循环语句和if条件语句找出低于平均分的分数。该题第1个循环的作用是求出平均分av,第2个循环的作用是找出低于平均分的成绩记录并存入below数组中。
转载请注明原文地址:https://kaotiyun.com/show/QNDp777K
0

最新回复(0)