1051 complex multiplications (15 minutes)

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  (.

It 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

. 1 #include <stdio.h>
 2 #include <the iostream>
 . 3 #include < String .h>
 . 4 #include <the cmath>
 . 5  the using  namespace STD;
 . 6  
. 7  int main () {
 . 8      
. 9      
10      Double R1, P1, R2, P2, A, B;    
 . 11      
12 is      CIN R1 >> R2 >> >> P1 >> P2;
 13 is      
14      A = R1 * R2 * (COS (P1) * COS (P2) -sin (P1) * SiN (P2) );
 15      B = R1 * R2 * (COS (P1) * SiN (P2) + SiN (P1) * COS (P2));
 16      // two decimals, the number of the real and imaginary absolute value is less than 0.01, then , 0.00 instead of directly to the 
17      IF(fabs(a)<0.01)
18         printf("0.00");
19     else
20         printf("%.2lf",a);
21     
22     if(fabs(b)<0.01)
23         printf("+0.00i");    
24     else if(b<0)
25         printf("%.2lfi",b);
26     else
27         printf("+%.2lfi",b);
28     
29     return 0;
30 } 

 

 

Guess you like

Origin www.cnblogs.com/geyang/p/12272840.html