Editorial Staff - - C Programming Tutorial
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.
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
Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari View all posts by Editorial Staff