编写程序以使用C将两个复数相加
问题
如何添加两个复数,这些复数由用户使用C程序在运行时输入-
解决方案
复数是可以是实部和虚部的组合的数字。
它以a+ib的形式表示。
程序
例如,在将两个复数相加后,我们将其取为(4+2i)和(5+3i),结果为9+5i。
#include输出结果struct complexNumber{ int realnumber, imaginarynumber; }; int main(){ struct complexNumber x, y, z,p; printf("enter first complex number x and y\n"); scanf("%d%d", &x.realnumber, &x.imaginarynumber); printf("enter second complex number z and p\n"); scanf("%d%d", &y.realnumber, &y.imaginarynumber); z.realnumber =x.realnumber + y.realnumber; z.imaginarynumber =x.imaginarynumber +y.imaginarynumber; printf("Sum of the complex numbers: (%d) + (%di)\n", z.realnumber, z.imaginarynumber); return 0; }
Enter first complex number x and y. 2 3 Enter second complex number z and p. 4 5 Sum of the complex numbers: (6) + (8i)
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下