Examples of Complex Number Type in C++2 min read

<complex> header file is used for declaring a complex number in C++.

We can declare the complex number by using complex(3,4) where 3 is a real number and 4 is imaginary part.

There are three real types in complex numbers. They are float complex, double complex, long double complex.

This section on C++ interview questions and answers focuses on “Complex Number Type”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams.

These questions can be attempted by anyone focusing on learning C++ programming language.

They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.



C++ Code:

Output: In this program, we are finding the square of the complex number.


C++ Code:

Output: We are just copying the value of c_int into c_double, So it’s printing as (4,5).


C++ Code:

Output: We are multiplying the complex number by 2.


C++ Code:

Output:  We are adding the two complex numbers and printing the result.



Output: In this program, we are adding both complex number and finding the square root of it.


C++ Code:

Output: imag part will return the imaginary part of the complex number.


Leave a Comment