21xrx.com
2024-03-28 20:42:22 Thursday
登录
文章检索 我的文章 写文章
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程序将两个复数相加输出:

  
  
下一篇: C程序打印日期

评论区

{{item['qq_nickname']}}
()
回复
回复