有一个一维数组,内放10个学生的成绩,编写一个函数,求平均分,最高分,最低分(要求用指针实现
展开全部
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) ;
}
希望能帮助到你
{
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) ;
}
希望能帮助到你
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询