C program to add two complex numbers

  • برمجة سي c

C program to add two complex numbers

C program to add two complex numbers: this program performs addition of two complex numbers which will be entered by a user and then prints it. A user inputs real and imaginary parts of two complex numbers. In our program we will add real parts and imaginary parts of complex numbers and prints the complex number, 'i' is the symbol used for iota. For example, if a user inputs two complex numbers as (1 + 2i) and (4 + 6 i) then the output of the program will be (5 + 8i). A structure is used to store a complex number.

الأجوبة

#include 
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;
}
هل كان المحتوى مفيد؟

القوائم الدراسية التي ينتمي لها السؤال

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...