PAT B brush Subjects path 1051 complex multiplications (15 minutes)

1051 complex multiplications (15 minutes)

Complex can be written as (A + Bi) of conventional form, where A is a real part, B is the imaginary unit, i is the imaginary unit, satisfies i ^ 2 = -1; can also be written in polar coordinates exponential (R × e (Pi)), where R is the complex modulus, P is the convergence angle, i is the imaginary unit, which is equivalent to a triangular form R (cos§ + isin§).
It is now given of two complex numbers R and P, the number of required output the product of two conventional forms.
Input format:
sequentially input plural R1 given in two in a row, P 1, among R2, P2, numbers separated by a space.
Output format:
in the form of a line in a conventional format of the output product of the two numbers A + Bi, the real and imaginary part 2 decimal places. Note: If B is negative, should be written A- | B | i form.
Sample input:
2.3 3.5 5.2 0.4
Output Sample:
-8.68-8.23i

When the focus is negative retained two is 0.00, the output is + 0.00i

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double r1,p1,r2,p2,a,b;
    scanf("%lf%lf%lf%lf",&r1,&p1,&r2,&p2);
    a=r1*r2*cos(p1+p2);
    b=r1*r2*sin(p1+p2);
    if(a+0.005>=0&&a<0)
        printf("0.00");
    else
        printf("%.2f",a);
    if(b>=0)
        printf("+%.2fi",b);
    else if(b+0.005>=0&&b<0)
        printf("+0.00i");
    else
        printf("%.2fi",b);
    return 0;
}

Published 73 original articles · won praise 0 · Views 538

Guess you like

Origin blog.csdn.net/derbi123123/article/details/103791966