从键盘上输入若干学生成绩(百分制整数),直到输入-1结束。求平均分并保留1位小数输出。使用while语句。

如题所述

在VC++6.0下运行的C语言程序,当输入负数结束,整数继续(这里没做0-100的限定,可以自己简单加上就行)
#include <stdio.h>
void main()
{
float sum=0;
float average=0;
int i=0;
int score=0;
while(score>-1)
{
scanf("%d",&score);
//printf("%d\n",score);
sum=sum+score;
i=i+1;
}
average=sum/i;
printf("average=%.1f\n",average);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-12
路过!!!!!!!