Use cout to achieve decimal point output and retention control
Topic description
Input the grades of 5 students (integer) from the keyboard and find their average grade (floating point number, one decimal place).
Input description:
Enter 5 integers in a row (range 0~100) in one line, separated by spaces.
Output description:
one line, output the average of 5 numbers (with one decimal place).
Example 1
Input
75 80 43 67 96
Output
72.2
#include<iostream>
#include<iomanip>
using namespace std;
int main ()
{
int a,b,c,d,e;
double average;
cin>>a>>b>>c>>d>>e;
average=(a+b+c+d+e)/5.0;
//强制显示小数位数
cout.setf(ios::fixed);
cout.precision(1);
cout<<average;
//cout<<fixed<<setprecision(1)<<aveeage;
}