zl程序教程

您现在的位置是:首页 >  其他

当前栏目

习题 13.2 从键盘输入一批数值,要求保留3位小数,在输出时上下行小数点对齐。

输出 要求 习题 数值 保留 小数 对齐 小数点
2023-09-14 09:06:56 时间

C++程序设计(第三版) 谭浩强 习题13.2 个人设计

习题 13.2 从键盘输入一批数值,要求保留3位小数,在输出时上下行小数点对齐。

代码块:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	double a, b, c;
	cout<<"enter a, b, c: ";
	cin>>a>>b>>c;
	cout<<setiosflags(ios::fixed)<<setprecision(3)
		<<setfill(' ')<<setw(10)<<a<<'\n'
		<<setfill(' ')<<setw(10)<<b<<'\n'
		<<setfill(' ')<<setw(10)<<c<<endl;
	system("pause");
	return 0;
}