输出保留两位小数
1.引入头文件
#include <iomanip>
2.格式化输出:
cout<<setiosflags(ios::fixed)<<setprecision(2);
你题目的解答代码如下:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int i = 8, j = 12;
double x = 3.14, y = 90;
cout << setw(7) << i << setw(7) << j << endl;
cout << setw(7) << setiosflags(ios::fixed) << setprecision(2) << x << setw(7) << y << endl;
return 0;
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!