01 complex arithmetic operations

 1 #include<stdio.h>
 2 #include<math.h>
 3 struct Complex {
 4     double a;//实部
 5     double b;//虚部
 6 };
 7 void initComplex(double x, double y) {
 8     printf("%.2f+%.2f*i\n", x, y);
 9 }
10 void add(struct Complex complex1, struct Complex complex2) {
11     double sumA = complex1.a +complex2.a;
 12 is      Double sumB + = complex1.b complex2.b;
 13 is      the printf ( " two complex numbers is: \ n- " );
 14      initComplex (SUMA, sumB);
 15  }
 16  void minus ( struct Complex complex1, struct complex2 complex) {
 . 17      Double minusA = complex1.a - complex2.a;
 18 is      Double minusB = complex1.b - complex2.b;
 . 19      the printf ( " difference of two complex numbers is: \ n- " );
 20 is      initComplex (minusA, minusB) ;
 21  }
22 is  void Multiply ( struct Complex complex1, struct Complex complex2) {
 23 is      Double Mula = complex1.a complex2.a * - * complex1.b complex2.b;
 24      Double MULB = complex1.b complex1.a * + * complex2.a complex2 .B;
 25      the printf ( " the product of two complex numbers is: \ n- " );
 26 is      initComplex (Mula, MULB);
 27      // complex multiplication formula z1 = a + bi, z2 = c + di, z1 * z2 = (ac -bd) + (AD + BC) I 
28  }
 29  void Division ( struct Complex complex1, struct Complex complex2) {
 30     Double diviA = (+ complex1.b complex2.a complex1.a * * complex2.b) / (POW (complex2.a, 2.0 ) + POW (complex2.b, 2.0 ));
 31 is      Double diviB = (* complex1.b complex2.a - complex1.a complex2.b *) / (POW (complex2.a, 2.0 ) + POW (complex2.b, 2.0 ));
 32      the printf ( " two complex quotient is: \ n- " );
 33 is      initComplex (diviA, diviB);
 34 is      // complex multiplication formula z1 = a + bi, z2 = c + di, z1 / z2 = (ac + bd) / (c ^ 2 + d ^ 2) + ((bc-ad) / (C + D ^ 2 ^ 2)) I 
35  }
 36  void main () {
 37 [      struct Complex complex1;
 38 is     struct Complex complex2;
 39      // complex1.a =. 1;
 40      // complex1.b = 2; 
41 is      the printf ( " real part of a complex enter: \ n- " );
 42 is      Scanf ( " % LF " , & complex1.a);
 43 is      the printf ( " Please enter the imaginary part of a complex number: \ n- " );
 44 is      Scanf ( " % LF " , & complex1.b);
 45      the printf ( " to get a first plural: ' ) ;
 46 is      initComplex (complex1.a, complex1.b);
 47  
48     the printf ( " Please enter the second the real part: \ n- " );
 49      Scanf ( " % LF " , & complex2.a);
 50      the printf ( " Please enter the second imaginary part of the complex: \ n- " ) ;
 51 is      Scanf ( " % LF " , & complex2.b);
 52 is      the printf ( " to obtain a second complex number: " );
 53 is      initComplex (complex2.a, complex2.b);
 54 is  
55      the Add (complex1, complex2);
 56 is      minus (complex1, complex2);
 57 is      Multiply (complex1, complex2);
 58     division(complex1, complex2);
59 }

 

Guess you like

Origin www.cnblogs.com/shanlu0000/p/12416765.html