#include<stdio.h>
void maxmin( float a[] , int length , float m[] );
int main()
{
float aa[5], m[3];
for (int i=0 ; i<5 ; i++)
{
printf ("请输入第%d个学生成绩:" , i+1);
scanf("%f",&aa[i]);
}
maxmin( aa , sizeof(aa)/sizeof(float) , m );
printf(" max=%f \n min=%f \n average=%f \n",m[0],m[1],m[2]);
return 0;
}
void maxmin( float a[] , int length , float m[] )
{
m[0]=a[0]; m[1]=a[0]; m[2]=a[0];
for ( int i=1 ; i<length ; i++ )
{
m[0] = m[0]<a[i] ? a[i] : m[0] ; //MAX
m[1] = m[1]>a[i] ? a[i] : m[1] ; //MIN
m[2] += a[i]; //累加
}
m[2] = m[2]/length;
} |
|