1. Which header file is used to declare the complex number?
A. complexnum
B. complex
C. complex number
D. complexarg
Answer: B
Explanation:
<complex> header file is used for declaring a complex number in C++.
2. How to declare the complex number?
A. (3, 4)
B. complex(3, 4)
C. (3, 4i)
D. (3, 4g)
Answer: B
Explanation:
We can declare the complex number by using complex(3,4) where 3 is a real number and 4 is imaginary part.
3. How many real types are there in complex numbers?
A. 1
B. 2
C. 3
D. 4
Answer: C
Explanation:
There are three real types in complex numbers. They are float complex, double complex, long double complex.
4. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
complex c1(4.0, 16.0), c2;
c2 = pow(c1, 2.0);
cout << c2;
return 0;
}
A. (-240, 128)
B. (240, 128)
C. (240, 120)
D. (240, -122)
Answer: A
Explanation:
In this program, we are finding the square of the complex number.
5. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
complex c_double(2, 3);
complex c_int(4, 5);
c_double *= 2;
c_double = c_int;
cout << c_double;
return 0;
}
A. (2, 3)
B. (4, 5)
C. (8, 15)
D. (8, 10)
Answer: B
Explanation:
We are just copying the value of c_int into c_double, So it’s printing as (4,5).
6. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
complex i(2, 3);
i = i * 6 / 3;
cout << i;
return 0;
}
A. (4, 6)
B. (2, 3)
C. (6, 12)
D. (6, 15)
Answer: A
Explanation:
We are multiplying the complex number by 2.
7. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
complex c1(4.0,3.0);
cout << "c1: " << c1;
complex c2(polar(5.0,0.75));
cout << c1 + complex(c2.real(),c2.imag());
return 0;
}
A. c1: (4,3)(7.65844,6.40819)
B. c1: (4,3)(7,6)
C. both c1: (4,3)(7.65844,6.40819) & c1: (4,3)(7,6)
D. c1: (5,3)(7,6)
Answer: A
Explanation:
We are adding the two complex numbers and printing the result.
8. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
complex c1(4.0, 3.0);
complex c2(polar(5.0, 0.75));
cout << (c1 += sqrt(c1)) << endl;
return 0;
}
A. (4.0, 3.0)
B. (6.12132, 3.70711)
C. (5.0, 0.75)
D. (5.0, 3.75)
Answer: B
Explanation:
In this program, we are adding both complex number and finding the square root of it.
9. Which of the following is not a function of complex values?
A. real
B. imag
C. norm
D. cartesian
Answer: D
Explanation:
Real is used for returning real part, imag for imaginary part and norm for calculating norm of a complex number. There is no such function Cartesian in complex header file.
10. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main ()
{
complex mycomplex (20.0, 2.0);
cout << imag(mycomplex) << endl;
return 0;
}
A. 2
B. 20
C. 40
D. 30
Answer: A
Explanation:
imag part will return the imaginary part of the complex number.