You are going to read a serial of real numbers (number with decimal point). The exact number of the numbers are not known.
Your program calculates the average of all the numbers, and prints the average which rounds to two decimal places.
There is at least one number to be processed.
##输入格式:
A serial of real numbers.
##输出格式:
A number rounds to two decimal places, which is the average of the serial.
Using C, the printf for this case is:
printf("%.2f\n", average);
##输入例子
1.0 2.1 3.2 4.3 5.4 6.5
##输出例子
3.75
代码如下:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double n;
double sum=0;
int count=0;
while(cin>>n)
{
sum+=n;
count++;
}
double average=sum/count;
cout<<fixed<<setprecision(2)<<average;
return 0;
}