#include
void main() // 改成 int main ()
{
int score, max, min, average, sum, i = 1;
scanf("%d\n", &score); // 如果这时候输入是 -1 呢
sum = max = min = score;
while (score != -1) { // 这种应该用 do while
scanf("%d", &score);
i++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
}
average = sum / i; // 平均分最好不要用 int
printf("%d%d%d%d", max, min, average, sum);
}
我修改了一下
#include
int main()
{
int score, max, min, sum, i;
double average;
printf("请输入分数\n");
scanf("%d", &score);
if (score == -1) return 0;
i = 0;
sum = 0;
max = min = score;
do {
i++;
if (score > max)
max = score;
if (score < min)
min = score;
sum += score;
scanf("%d", &score);
} while(score != -1);
average = (double)sum / (double)i;
printf("%d, %d, %f, %d\n", max, min, average, sum);
}
#include "stdio.h"
int main(int argv,char *argc[]){
int score,max,min,sum,i=1;//有改
double average;//增加
scanf("%d",&score);//有改
sum=max=min=score;
while(score!=-1){
//scanf("%d",&score);//删除
//i++;//删除
if(score>max) max=score;
if(scoresum+=score;
scanf("%d",&score);//添加
i++;//添加
}
average=sum/(i+0.0);//有改
printf("%d %d %f %d\n",max,min,average,sum);//有改
return 0;
}
运行样例:
//简单帮你修改了下
#include
void main()
{
int score,max,min,average,sum,i=1;
scanf("%d\n",&score);
sum = 0; //初始化为0
max=min=score;
while(score!=-1)
{
i++;
if(score>max) max=score;
if(score
scanf("%d",&score); //这个位置应调动下
}
average=sum/i;
printf("%d %d %d %d",max,min,average,sum); //加2个空格,这样结果更清晰
}