全部问题 > 当前问题

请问老师,我这个为什么错了???

#include <stdio.h>

#include <string.h>

int fun(int score[], int m, int below[])

{

int i,s=0;double arr=0.0;int n=0;

for(i=0;i<=m;i++)

s=s+score[i];

arr=s/m;

for(i=0;i<=m;i++)

if(score[i]<arr)

below[n++]=score[i];

return arr;







}


main( )

{  int i, n, below[9] ;void NONO ();

   int score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90} ;


   n = fun(score, 9, below) ;

   printf( "\nBelow the average score are: " ) ;

   for (i = 0 ; i < n ; i++)  printf("%d ", below[i]) ;

   NONO() ;

}


void NONO ()

{/* 本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/

  int i, j, n, below[10], score[10] ;

  FILE *rf, *wf ;


  rf = fopen("in.dat","r") ;

  wf = fopen("out.dat","w") ;

  for(i = 0 ; i < 10 ; i++) {

    for(j = 0 ; j < 10 ; j++) fscanf(rf, "%d", &score[j]) ;

    n = fun(score, 10, below) ;

    for(j = 0 ; j < n ; j++) fprintf(wf, "%d ", below[j]) ;

    fprintf(wf, "\n") ;

  }

  fclose(rf) ;

  fclose(wf) ;

}


啊啊啊Awhen 2017-8-16 17:17:25

共 2 个回答

qqq 2017-8-17 11:30:53

题目要求return的是n,你return的是arr。

啊啊啊Awhen 2017-8-25 09:29:29

回复 qqq

#include <stdio.h>

#include <string.h>

int fun(int score[], int m, int below[])

{

int i,s=0;float arr=0.0;int n=0;

for(i=0;i<=m;i++)

s=s+score[i];

arr=s/m;

for(i=0;i<=m;i++)

if(score[i]<arr)

below[++n]=score[i];

return n;

还是不对啊。。

问题来自: 编程题真题