一个很简单的标记控制循环程序!
#include<stdio.h>int main()
{
int counter=0;
int grade;
float sum=0;
while(1)
{
printf("Input the grade:");
scanf("%d",&grade);
if(grade!=-1)
{
sum = sum + grade;
counter++;
}
else
{
break;
}
}
printf("The average is:%d\n",sum/counter);
return 0;
}