#include stdioh void main int scoreimaxmin; float sum; found max=100; min=0; sum=0; printfInput number n; found
There are several errors in this code:
- The return type of the main function should be int, not void.
- The scanf function requires the address of the variable being read into, so the argument for scanf should be &score, not score.
- The loop should run for 10 iterations, not 9.
- The formula for calculating the average score should divide by 8, not 10, since the highest and lowest scores are being removed.
Corrected code:
#include <stdio.h>
int main( )
{
int score,i,max=0,min=100;
float sum=0;
printf("Input scores:\n");
for(i=1;i<=10;i++)
{
scanf("%d",&score); /*输入评委的评分*/
sum+=score; /*计算总分*/
if(score>max) max=score; /*通过比较筛选出其中的最高分*/
if(score<min) min=score; /*通过比较筛选出其中的最低分*/
}
printf("Canceled max score:%d\nCanceled min score:%d\n",max,min);
printf("Average score:%.3f\n",(sum-max-min)/8.0);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/blPQ 著作权归作者所有。请勿转载和采集!