# Add Two Complex Numbers C Program

## C Program To Add Two Complex Numbers

Learn How To Write A Code To Add Two Complex Numbers in C Programming Language. This C Program To Find Sum of Two Complex Numbers makes use of Structures and Arrays in C Language.

#### What are Complex Numbers?

A Complex Number is expresses in the format **A + Bi**, where **A** and **B** are **Real Numbers** and **i** is an I**maginary Variable**. In this expression, A is the real part whereas B is the imaginary part. The complex number should satisfy the equation **i ^{2} = -1.**

**Must Read: C Program For Evaluation of A Polynomial**

#### C Program To Add Two Complex Numbers using Structures

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 30 31 32 | #include <stdio.h> struct complex_number { int real, imaginary; }; int main() { struct complex_number first_number, second_number, third_number; printf("\nEnter Values For First Complex Number\n"); printf("Enter value of A:\t"); scanf("%d",&first_number.real); printf("Enter value of B:\t"); scanf("%d",&first_number.imaginary); printf("\nEnter Values For First Complex Number\n"); printf("Enter value of C:\t"); scanf("%d",&second_number.real); printf("Enter value of D:\t"); scanf("%d",&second_number.imaginary); third_number.real = first_number.real + second_number.real; third_number.imaginary = first_number.imaginary + second_number.imaginary; if(third_number.imaginary >= 0 ) { printf("\nAddition of Complex Numbers:\t%d + %di\n", third_number.real, third_number.imaginary); } else { printf("\nAddition of Complex Numbers:\t%d + %di\n", third_number.real, third_number.imaginary); } return 0; } |

#### C Program To Calculate Sum of Complex Numbers using Array

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 | #include <stdio.h> int main() { int arr[3][3]; int first_number[2][2], second_number[2][2], third_number[2][2]; printf("\nEnter Values For First Complex Number\n"); printf("Enter value of A:\t"); scanf("%d",&arr[0][0]); printf("Enter value of B:\t"); scanf("%d",&arr[0][1]); printf("\nEnter Values For First Complex Number\n"); printf("Enter value of C:\t"); scanf("%d",&arr[1][0]); printf("Enter value of D:\t"); scanf("%d",&arr[1][0]); arr[2][0] = arr[0][0] + arr[0][1]; arr[2][1] = arr[1][0] + arr[1][1]; if(arr[2][0] && arr[2][1] >= 0 ) { printf("\nAddition of Complex Numbers:\t%d + %di\n", arr[2][0],arr[2][1]); } else { printf("\nAddition of Complex Numbers:\t%d + %di\n", arr[2][0],arr[2][1]); } return 0; } |

**Must Read:C Program To Find Roots of Quadratic Equation**

#### Output

If you have any compilation errors or doubts in this C Program To Add Two Complex Numbers, let us know about in the Comment Section below.

I feel that adding two complex nunbers using structures is much better than using arrays. It looks for efficient and eay to understand.