PAT Basic 1051 complex multiplications (15 points)

Complex can be written as  (of conventional form, where  A is a real part, B is the imaginary part, I is the imaginary unit, satisfies  1; can also be written in exponential form in polar coordinates  (wherein  R is the complex modulus, P is the argument, I It is the imaginary unit, which is equivalent to a triangular form  (.

Is now given of two complex numbers  R and  P, the number of required output the product of two conventional forms.

Input formats:

Given in two successively input in a row of a plurality of  R & lt . 1 P . 1 R & lt 2 P 2 , separated by a space between digits.

Output formats:

Following the row  A+Bi format of the output of a conventional form of the product of two numbers, the real and imaginary part 2 decimal places. Note: If you  B are negative, should be written  A-|B|i in the form.

Sample input:

2.3 3.5 5.2 0.4

Sample output:

-8.68-8.23i
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double a,ai,b,bi;
    cin>>a>>ai>>b>>bi;
    double val=a*b*cos(ai+bi);
    double vali=a*b*sin(ai+bi);
    if(fabs(val)<0.01) val=0;
    if(fabs(vali)<0.01) vali=0;
    printf("%.2f",val);
    if(vali>=0) cout<<"+";
    printf("%.2fi",vali);
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11410299.html