33,311
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
main()
{
float grade, counter, total,average;
counter = 0, total = 0;
while (grade != -1)
{
printf("Enter -1 to end, please enter grade: ");
scanf("%f", &grade);
counter = counter + 1;
total = total + grade;
}
++ total, -- counter;
average = total / counter;
printf("The counter is %f, The average is %f.\n", counter, average);
}
while (abs(grade + 1) < 10e-5)
//精度原因。
//我计算机上用grade != -1木有问题
#include <stdio.h>
#include <math.h>
main()
{
float grade, counter, total,average;
counter = 0, total = 0;
while (fabs(grade + 1) > 1e-6)
{
printf("Enter -1 to end, please enter grade: ");
scanf("%f", &grade);
counter = counter + 1;
total = total + grade;
}
++ total, -- counter;
average = total / counter;
printf("The counter is %f, The average is %f.\n", counter, average);
}