c语言,求复数之积。利用结构变量求解如下两组复数之积。 za={3,4}, zb={5,6} za={10,20}, zb={30,40} **输出格式要求:"(%d+%di)*(%d+%di)=" "(%d+%di)\n" 程序运行示例如下: (3+4i)*(5+6i)=(-9+38i) (10+20i)*(30+40i)=(-500+1000i)
时间: 2024-02-28 20:57:51 浏览: 66
以下是求解两组复数之积的 C 语言代码:
```c
#include <stdio.h>
struct Complex {
int real;
int imag;
};
int main() {
struct Complex za1 = {3, 4};
struct Complex zb1 = {5, 6};
struct Complex za2 = {10, 20};
struct Complex zb2 = {30, 40};
// 计算第一组复数之积
int real1 = za1.real * zb1.real - za1.imag * zb1.imag;
int imag1 = za1.real * zb1.imag + za1.imag * zb1.real;
printf("(%d+%di)*(%d+%di)=(%d+%di)\n", za1.real, za1.imag, zb1.real, zb1.imag, real1, imag1);
// 计算第二组复数之积
int real2 = za2.real * zb2.real - za2.imag * zb2.imag;
int imag2 = za2.real * zb2.imag + za2.imag * zb2.real;
printf("(%d+%di)*(%d+%di)=(%d+%di)\n", za2.real, za2.imag, zb2.real, zb2.imag, real2, imag2);
return 0;
}
```
输出结果为:
```
(3+4i)*(5+6i)=(-9+38i)
(10+20i)*(30+40i)=(-500+1000i)
```
阅读全文