#include
int deal(int a[],int m,int up[]);
int main()
{
int i,j,count=0;
int score[]={1,2,3,4,5,6,7,8,9,0,10},up[100]={-1};
count=deal(score,11,up);
printf("%d\n",count);
for(i=0;i
return 0;
}
int deal(int a[],int m,int up[])
{
double sum=0,aver;
int i=0,count=0,j=0;
while(i
sum=sum+a[i];
i++;
}
aver=sum*1.0/m;
for(i=0;i
if(a[i]>aver)
{
count++;
up[j]=a[i];
j++;
}
}
return count;
}
输出为:
5
6 7 8 9 10
但是数字要是大且多得话,就得考虑溢出了!
#include
int main()
{
int m,i,j=0,a[100],*up,score[100],sum=0;
double aver;
up=a;
printf("输入m\n");
scanf("%d",&m);
printf("输入成绩(为整数)\n");
for(i=0;i
for(i=0;i
aver=(double)sum/m;
printf("%lf\n",aver);
printf("高于平均分的有\n");
for(i=0;i
if(score[i]>aver)
{ a[j]=score[i];
printf("%d\n",a[j]);
j++;
}
}
return 0;
}
#include
int highaverage(float s[],float stu[],int x);
int main()
{
int m,n;
float score[20],up[20];
printf("input M:");
scanf("%d",&m);
for(int i=0;i
printf("score[%d]=",i);
scanf("%f",&score[i]);
}
n=highaverage(score,up,m);
for(int j=0;j
return 0;
}
int highaverage(float s[],float stu[],int x)
{
float average,sum;
int num=0;
for(int i=0;i
sum+=s[i];
}
average=sum/x;
for(int j=0;j
if(s[j]>average)
{stu[num]=s[j];num++;}
}
return num;
}
int upp[100];
int* up=upp;
int upaver(int s[],int* up,int m){
int i,cnt,aver,sum=0;
for(i=0;i
aver = sum/m;
for(i=0;i
*up++=s[i];
cnt++;
}
}
return cnt;
}
调用时,int n = upaver(score,up, m);