Today we are going to share a **C program to add two complex numbers**. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C program to add two complex numbers with the output.

We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.

C

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <stdio.h> struct complex { int realpart, imaginary; }; main() { struct complex a, b, c; printf("Enter value of a and b complex number a + ib.\n"); printf("value of complex number a is = "); scanf("%d", &a.realpart); printf("value of complex number b is = "); scanf("%d", &a.imaginary); printf("Enter value of c and d complex number c + id.\n"); printf("value of complex number c is = "); scanf("%d", &b.realpart); printf("value of complex number d is = "); scanf("%d", &b.imaginary); c.realpart = a.realpart + b.realpart; c.imaginary = a.imaginary + b.imaginary; if (c.imaginary >= 0) printf("complex numbers sum is = %d + %di\n", c.realpart, c.imaginary); else printf("complex numbers sum = %d %di\n", c.realpart, c.imaginary); return 0; } |

Enter value of a and b complex number a + ib.

value of complex number a is = 10

value of complex number b is = 5

Enter value of c and d complex number c + id.

value of complex number c is = 20

value of complex number d is = 25

complex numbers sum is = 30 + 30i

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

- C program to implement bit flipping
- C program to implement hashing
- C program to implement SJF algorithm
- stdio.h library functions list in c
- conio.h functions list in c
- C program remove spaces, blanks from a string
- How to write c program code for pow
- Program to delete n characters from a given position in a given string
- C program to solve the Number of stopping station problem
- C implementation of inserting a new node to a link list