Bootstrap

C程序---计算两复数之积(结构体)

 

 

复数乘法法则

规定复数的乘法按照以下的法则进行:

设z1=a+bi,z2=c+di(a、b、c、d∈R)是任意两个复数,那么它们的积(a+bi)(c+di)=(ac-bd)+(bc+ad)i

#include<stdio.h>
#include<string.h>
#define N 10



int main()
{
      struct plural
      {
            int real ;
            int imag ;
      };
      int _real,_imag;
      struct plural num1 = {3,4};
      struct plural num2= {5,6};
      printf("%d + %d i \n",num1.real ,num1.imag);
      printf("%d + %d i \n",num2.real ,num2.imag);
      _real = num1.real * num2.real - num1.imag * num2.imag ;
      _imag = num1.imag* num2.real + num1.real * num2.imag ;
      printf("%d + %d i \n",_real ,_imag);


return 0 ;
}

 

;