若两个复数分别为:c1=x1+y1i和c2=x2+y2i,则它们的乘积为 c1×c2=(x1x2−y1y2)+(x1y2+x2y1)i。
本题要求实现一个函数计算两个复数之积。
函数接口定义:
复制代码
1
2double result_real, result_imag; void complex_prod( double x1, double y1, double x2, double y2 );
其中用户传入的参数为两个复数x1
+y1
i和x2
+y2
i;函数complex_prod
应将计算结果的实部存放在全局变量result_real
中、虚部存放在全局变量result_imag
中。
裁判测试程序样例:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include<stdio.h> double result_real, result_imag; void complex_prod( double x1, double y1, double x2, double y2 ); int main(void) { double imag1, imag2, real1, real2; scanf("%lf %lf", &real1, &imag1); scanf("%lf %lf", &real2, &imag2); complex_prod(real1, imag1, real2, imag2); printf("product of complex is (%f)+(%f)in", result_real, result_imag); return 0; } /* 你的代码将被嵌在这里 */
输入样例:
复制代码
1
21 2 -2 -3
输出样例:
复制代码
1product of complex is (4.000000)+(-7.000000)i
最后
以上就是称心电灯胆最近收集整理的关于5-1 使用函数计算两个复数之积 (10 分)的全部内容,更多相关5-1内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复