sicily 6275. 求平均分

Description

编程求解一个小班同学的测验平均分,得分为0到100之间的整数,由于可能有同学请假等原因,出席同学人数不定,输入以-1作为结束。求解平均数,保留1位小数输出。

Input

输入分数,直到输入-1结束。

Output

输出所有分数的平均值,保留1位小数

就算对我这种菜鸟也是白痴题了……注意设成浮点型就OK。一次AC

View Code
 1 #include<stdio.h>
 2 int main()
 3 {
 4     float n, total=0.0; 
 5     int counter=0;
 6     while( scanf("%f" , &n) && ( n + 1 >= 0.000001 ) )
 7     {
 8         total = total + n;
 9         counter++;
10     }
11     printf("%.1f\n", total/counter );
12     return 0;
13 }                                 
原文地址:https://www.cnblogs.com/joyeecheung/p/2750458.html