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-13 22:05:53 浏览: 65
C语言程序设计-计算并输出给定整数的所有因子之积(包括自身);规定这个整数的值不大于50;
5星 · 资源好评率100%
以下是求解复数之积的 C 语言代码:
```c
#include <stdio.h>
struct complex {
int real;
int imag;
};
int main() {
struct complex za = {3, 4};
struct complex zb = {5, 6};
struct complex zc = {10, 20};
struct complex zd = {30, 40};
// 计算第一组复数之积
struct complex res1 = {0, 0};
res1.real = za.real * zb.real - za.imag * zb.imag;
res1.imag = za.real * zb.imag + za.imag * zb.real;
printf("(%d+%di)(%d+%di)= (%d+%di)\n", za.real, za.imag, zb.real, zb.imag, res1.real, res1.imag);
// 计算第二组复数之积
struct complex res2 = {0, 0};
res2.real = zc.real * zd.real - zc.imag * zd.imag;
res2.imag = zc.real * zd.imag + zc.imag * zd.real;
printf("(%d+%di)(%d+%di)= (%d+%di)\n", zc.real, zc.imag, zd.real, zd.imag, res2.real, res2.imag);
return 0;
}
```
输出结果为:
```
(3+4i)(5+6i)= (-9+38i)
(10+20i)(30+40i)= (-500+1000i)
```
阅读全文