输入示例:
5
1 2 3 4 5
输出示例:
max:5.00
min:1.00
aveg:3.00
#include<stdio.h>
int m,n,L,M,h,l;
int high,low;
float score[9],stu;
int main()
{
void ave_stu(void);//计算平均值
void highest();//计算最大值
void lowest();//计算最小值
scanf(" %d",&M); //数据个数
for(int j=0;j<M;j++)
{
scanf("%f",&score[j]);
}
ave_stu();
lowest();
highest();
printf("max:%.2f\n",h);
printf("min:%.2f\n",l);
printf("aveg:%.2f\n",stu);
}
void ave_stu(void)//计算平均值
{
int j;
float s;
for(j=0,s=0;j<M;j++)
{
s+=score[j];
}
stu=s/M;
}
void highest()//计算最大值
{ int i,j;
float h;
h=score[0];
for(j=0;j<M;j++)
{
if(score[j]>h)
h=score[j];
}
}
void lowest()//计算最小值
{
int i,j;
float l;
l=score[0];
for(j=0; j<M; j++)
{
if(score[j]<l)
l=score[j];
}
}
代码贴完自己读一读,能看清楚不
少好几个括号
你的h和l是局部变量呀
不要在函数里重新定义h和l