C程序将两个复数相加
2021-07-07 10:11:01
深夜i
--
--
C
程
序
将
两
个
复
数
相
加
将两个复数相加的 C 程序:该程序执行用户输入的两个复数的相加,然后将其打印出来。 用户输入两个复数的实部和虚部。 在我们的程序中,我们将添加复数的实部和虚部并打印复数,'i' 是用于 iota 的符号。 例如,如果用户输入两个复数为 (1 + 2i) 和 (4 + 6 i),则程序的输出将为 (5 + 8i)。 结构体用于存储复数。
C语言复数程序
#include <stdio.h>
struct complex
{
int real, img;
};
int main()
{
struct complex a, b, c;
printf("Enter a and b where a + ib is the first complex number.\n");
scanf("%d%d", &a.real, &a.img);
printf("Enter c and d where c + id is the second complex number.\n");
scanf("%d%d", &b.real, &b.img);
c.real = a.real + b.real;
c.img = a.img + b.img;
printf("Sum of the complex numbers: (%d) + (%di)\n", c.real, c.img);
return 0;
}
下载添加复数程序可执行文件。
C程序将两个复数相加输出:
上一篇:
idea打包java可执行jar包
下一篇:
C程序打印日期
评论区