56.指针-指针的定义与使用

98809b03efd74c1f985d515db52b416a.png

07ae3b5654654a5c9613061cd1e8f0ab.png 

 c1f6b378ea6240e8b5475e37cd6c57b0.png

 26a445a1a947425d8a8027ac64a95acc.png

3a34f30b55ec431994bb7e1e2d92a8a3.png 

2c7926e64b7242aba3be9ec9ea53e0f1.png 

7cb2e1625db543609b3aef26876d2475.png 

e70090c506a84d70ac611f7b969be835.png 

98f1f604beb94fe5aaf7d40e5dc5f419.png 

d5f0c8fc9ff44ffdb7a79a2faab83e6f.png 

9fe398720d894a1cb1370ba81aae0020.png 

5fc16c264b784c8abff40be8d3fbe144.png 

 

 

以下是完整的代码实现: ```c #include <stdio.h> // 定义结构体 struct complex { double real; double imag; }; // 加法 void complex_add(struct complex *c1, struct complex *c2, struct complex *result) { result->real = c1->real + c2->real; result->imag = c1->imag + c2->imag; } // 减法 void complex_sub(struct complex *c1, struct complex *c2, struct complex *result) { result->real = c1->real - c2->real; result->imag = c1->imag - c2->imag; } // 乘法 void complex_mul(struct complex *c1, struct complex *c2, struct complex *result) { result->real = c1->real * c2->real - c1->imag * c2->imag; result->imag = c1->real * c2->imag + c1->imag * c2->real; } // 除法 void complex_div(struct complex *c1, struct complex *c2, struct complex *result) { double denominator = c2->real * c2->real + c2->imag * c2->imag; result->real = (c1->real * c2->real + c1->imag * c2->imag) / denominator; result->imag = (c1->imag * c2->real - c1->real * c2->imag) / denominator; } int main() { // 定义变量 struct complex c1, c2, result; char op; // 读入数据 scanf("%lf %lf %lf %lf %c", &c1.real, &c1.imag, &c2.real, &c2.imag, &op); // 进行运算 switch (op) { case 'a': complex_add(&c1, &c2, &result); break; case 'b': complex_sub(&c1, &c2, &result); break; case 'c': complex_mul(&c1, &c2, &result); break; case 'd': complex_div(&c1, &c2, &result); break; default: printf("无效操作符\n"); return 0; } // 输出结果 printf("%.3lf%+.3lfi\n", result.real, result.imag); return 0; } ``` 使用方法:将上述代码保存为一个名为 `complex.c` 的文件,然后使用 C 语言编译器编译运行即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值