1721 - 中级第一课——所有偶数的平均值
编程计算所有输入的数中偶数的平均值。输入数据以-1结束。
Input
一行,若干个数
Output
一行,一个数,保留两位小数
Examples
Input
12 21 12 3 9 12 -1
Output
12.00
Solution C++
#include<iostream> #include<cstdio> using namespace std; int main() { int x,t=0; double ans=0; while (cin>>x && x!=-1) if (x%2==0) { ans+=x; t++; } printf("%.2lf\n",ans/t); return 0; }