1. 给定程序中,函数fun的功能是:计算形参x所指数组中的平均值(规定所有数均为正数),作为函数值返回,并将大于平均值的数放在形参y所指数组中

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    #define   N   10
    double fun(double x[],double *y)
    { int i,j; double av;
    /**********found**********/
    av=0.0;
    /**********found**********/
    for(i=0; i<N; i++) av = av +x[i]/N ;
    for(i=j=0; i<N; i++)
    /**********found**********/
    if(x[i]>av) y[j++]= x[i];
    y[j]=-1;
    return av;
    }
  1. 给定程序中,函数func的功能是:计算x所指数组中N个数的平均值(规定所有数均为正数),平均值通过形参返回主函数,将小于平均值且最接近平均值的数作为函数值返回,在主函数中输出。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    #define   N   10
    double fun(double x[],double *av)
    { int i,j; double d,s;
    s=0;
    for(i=0; i<N; i++) s = s +x[i];
    /**********found**********/
    *av=s/N;
    d=32767;
    for(i=0; i<N; i++)
    if(x[i]<*av && *av - x[i]<=d){
    /**********found**********/
    d=*av-x[i]; j=i;}
    /**********found**********/
    return x[j];
    }