当结果中a或者b小于0,大于0.005时,保留两位小数会输出-0.00,但应输出0.00。
#include <iostream>
#include <math.h>
using namespace std; int main()
{
double r1, p1, r2, p2;
cin >> r1 >> p1 >> r2 >> p2;
double a1 = r1 * cos(p1), b1 = r1 * sin(p1);
double a2 = r2 * cos(p2), b2 = r2 * sin(p2);
double a3 = a1 * a2 - b1 * b2;
double b3 = a1 * b2 + b1 * a2;
if (a3 > -0.005 && a3 < ) a3 = -a3;
if (b3 > -0.005 && b3 < ) b3 = -b3;
if (b3 < )
printf("%.2f%.2fi", a3, b3);
else
printf("%.2f+%.2fi", a3, b3);
return ;
}