这道题用到小数点后几位,我忘了头文件。头文件是#include[HTML_REMOVED],对应的语句是cout << fixed << setprecision(2) << x+y;还可以用printf,printf(“%.2lf”,x+y);
这道题有两种写法:
方法1:
#include<iostream>
#include<iomanip>
using namespace std;
double add(double x, double y)
{
cout << fixed << setprecision(2) << x+y;
}
int main()
{
//freopen("xxx.in","r",stdin);
//freopen("yyy.out","w",stdout);
double x,y;
cin >> x >> y;
add(x,y);
//fclose(stdin);
//fclose(stdout);
return 0;
}
方法2:
#include<iostream>
#include<iomanip>
using namespace std;
double add(double x, double y)
{
printf("%.2lf",x+y);//cout << fixed << setprecision(2) << x+y;
}
int main()
{
//freopen("xxx.in","r",stdin);
//freopen("yyy.out","w",stdout);
double x,y;
cin >> x >> y;
add(x,y);
//fclose(stdin);
//fclose(stdout);
return 0;
}