Discussion Forums

New User? Please read instructions!

C program to add two complex numbers  

  RSS

thiyagarajan.s
Active Member
Joined: 4 months  ago
Posts: 14
27/01/2017 10:05 am  

C program to add two complex numbers


ReplyQuote
prakash
Eminent Member
Joined: 4 months  ago
Posts: 20
16/02/2017 1:45 pm  

C program to add two complex numbers:

 

#include <stdio.h>

struct complex

{

     int real, img;

};

 

int main()

{

     struct complex a, b, c;

 

     printf("Please enter first complex number\n");

     printf("Enter Real part of the 1st complex number\n");

     scanf("%d", &a.real);

     printf("Enter Imaginary part of the 1st complex number without i\n");

     scanf("%d", &a.img);

     printf("Please enter second complex number\n");

     printf("Enter Real part of the 2nd complex number\n");

     scanf("%d", &b.real);

     printf("Enter Imaginary part of the 2nd complex number without i\n");

     scanf("%d", &b.img);

 

     c.real = a.real + b.real;

     c.img = a.img + b.img;

 

     if ( c.img >= 0 )

          printf("The sum of two complex numbers = %d + %di\n",c.real,c.img);

     else

          printf("The sum of two complex numbers = %d %di\n",c.real,c.img);

 

     return 0;

}

 

Output:

Please enter first complex number

Enter Real part of the 1st complex number

2

Enter Imaginary part of the 1st complex number without i

4

Please enter second complex number

Enter Real part of the 2nd complex number

6

Enter Imaginary part of the 2nd complex number without i

8

The sum of two complex numbers = 8 + 12i

 


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!