1051 复数乘法 (15 分)测试点2,3

#include<math.h>
#include<iostream>
using namespace std;
int main() {
	double R1, P1, R2, P2, tmp1,tmp2;
	scanf("%lf %lf %lf %lf", &R1, &P1, &R2, &P2);
	tmp1 = R1 * cos(P1)*R2*cos(P2) - R1 * sin(P1)*R2*(sin(P2));
	if (tmp1 > -0.005&&tmp1 < 0)tmp1 = 0;
	printf("%.2f", tmp1);
	tmp2 = R1 * cos(P1)*R2*sin(P2) + R2 * cos(P2)*R1*sin(P1);
	if (tmp2 > -0.005&&tmp2 < 0)tmp2 = 0;
	tmp2 >= 0 ? printf("+%.2fi", tmp2) : printf("%.2fi", tmp2);
	return 0;
}

测试点2,3主要问题就是对-0.00的处理。
因为是用的%.2f,也就是常说的四舍五入,那么问题是-0.0044四舍五入以后是-0.00,但是带了负号,所以需要手动归零。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值