#include <stdio.h>
int main()
{
int people; //多少人數(shù)
int grade; //輸入的成績(jī)
int total; //成績(jī)的總和
float average; //成績(jī)的平均
people=0;
total=0;
printf("Enter grade ,-1 to end: ");
scanf("%d",&grade);
//迴圈如果不等於-1則繼續(xù)執(zhí)行
while(grade!=-1){
total=total+grade;
people++;
printf("Enter grade ,-1 to end: ");
scanf("%d",&grade);
}
//如果人數(shù)不等於0,就開始計(jì)算平均
if(people!=0){
average = (float)total/people;
printf("Class average is %.2f\n",average);
}
else{
printf("No grades were entered\n");
}
return 0;
}