记:固定(小数点后的)位数的写法(输入输出流)

描述
Calculate a × b.

输入
The input will consist of a series of pairs of floating point numbers a and b,separated by a space, one pair of floating point numbers per line.

输出
For each pair of input floating point numbers a and b you should output the product of a and b in one line,and with one line of output for each line in input.

Output should be rounded to 3 digits after decimal point.

样例输入
1.1 1.1

1 0

1.234 5.678

样例输出
1.210

0.000

7.007

代码:

#include<iostream>
#include<iomanip>/*这个头文件是声明一些 “流操作符”的,
常用的有:
setw(int):设置显示宽度。
left//right:设置左右对齐。
setprecision(int):设置浮点数的精确度。*/

using namespace std;
int main()
{
	double a, b;
	while (cin >> a >> b)
	{
	cout<<fixed << setprecision(3)<< a * b<<endl;/*setprecision(3)是改为3精度,加了fixed意味着是固定点方式显示,
	所以这里的精度指的是小数位。*/
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值