A complex number is also a multivalue object. It consists of two parts: real part and imaginary part. The imaginary part carries symbol i which is equal to √-1 . A complete number is written as sum of the real part and the imaginary part as shown below.
Cl = x + iy
C2 = u + iv
Here, Cl and C2 are two complex numbers. The real part of number C1 is x and its imaginary part is y. Similarly, u is the real part of complex number C2 and v is its imaginary part. When two complex numbers C1 and C2 are added, the real part of C1 is added to the real part of C2, while the imaginary part of C1 is added to imaginary part of C2 in the following manner:
Cl + C2 = x + u + i(y + v)
Similarly, while performing subtraction (C1 - C2), the real part ofC2 is subtracted from the real part of C1 and the imaginary part of C2 is subtracted from the imaginary part of C1 as illustrated below.
C1 - C2 = x - u + i(y - v)
These operations may be carried out with the help of a function which returns structures. Program provides an example of performing these operations.
#include<stdio.h>
#include<math.h>
struct Complex //Declaration of structure for complex number
{
float Real;
float Imag;
} ;
//Addition of complex numbers
struct Complex Add (struct Complex C1, struct Complex C2)
{
struct Complex C3;
C3.Real =C1.Real+ C2.Real; //Function definition for addition.
C3.Imag = C1.Imag + C2.Imag;
return C3;
}
//Subtraction of complex numbers
struct Complex Sub (struct Complex C1, struct Complex C2)
{
struct Complex C3;
C3.Real =C1.Real - C2.Real;
C3.Imag = C1.Imag - C2.Imag;
return C3;
}
void main()
{
struct Complex A, B, C, D, P;
clrscr();
A.Real = 15; //A is complex number A= 15 + i10
A.Imag = 10;
B.Real = 8; // B is a complex number B 8 + i6
B.Imag = 6;
C = Add (A, B);
D = Sub (A,B);
printf("C.Real = %f\t C.Imag = %f\n", C.Real, C.Imag);
printf("D.Real = %f\t D.Imag =%f\n", D.Real, D.Imag);
}
Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Related Articles
Basic Courses
Advance Courses