PAT乙级1051

题目链接

未接触过的

题目中要求实部和虚部均保留 2 位小数,故当这两个部分的绝对值<0.01时,应该赋值为0(测试点2、3)

实现


#include <cstdio>
#include <cmath>
using namespace std;


int main()
{
	double r1, p1, r2, p2,A,B,r,p;
	scanf("%lf %lf %lf %lf", &r1, &p1, &r2, &p2);
	r = r1*r2;
	p = p1 + p2;
	A = r*cos(p);
	B = r*sin(p);
	if (abs(A) < 0.01)
		A = 0;
	if (abs(B) < 0.01)
		B = 0;
	if (B < 0)
		printf("%.2f%.2fi", A, B);
	else
		printf("%.2f+%.2fi", A, B);

    return 0;
}


猜你喜欢

转载自blog.csdn.net/DoctorLDQ/article/details/86571932