有一个一维数组,内放10个学生的成绩,编写一个函数,求平均分,最高分,最低分(要求用指针实现

2024-11-01 16:29:27
推荐回答(1个)
回答1:

int main ()
{
float *grade = (float *)malloc(10*sizeof(float)) ;

int i =0;

float max = 0,min = 100,average = 0 ;

float sum = 0 ;

printf("Please enter 10 grades...\n") ;

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

{
scanf("%f",&grade[i]) ;

}

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

{
sum += grade[i] ;

if(min >grade[i])

{
min = grade[i] ;

}

if(max < grade[i])

{
max = grade[i] ;
}

}

average = sum/10.0 ;

printf("min = %f,max =%f,average = %f\n",min,max,average) ;

}

希望能帮助到你