Complex Number Type(C++ Programming ) Questions and Answers
Question 1.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
complex mycomplex (20.0, 2.0);
7.
cout
- 2
- 20
- 40
- None of the mentioned
Explanation:-
Answer: Option A. -> 2imag part will return the imaginery part of the complex number.
Output:
$ g++ comp5.cpp
$ a.out
2
Explanation:-
Answer: Option D. -> cartesianNone.
Question 3.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
complex c1(4.0, 3.0);
7.
complex c2(polar(5.0, 0.75));
8.
cout
- (4.0, 3.0)
- (6.12132, 3.70711)
- (5.0, 0.75)
- None of the mentioned
Explanation:-
Answer: Option B. -> (6.12132, 3.70711)In this program, we are adding both complex number and finding the square root of it.
Output:
$ g++ comp4.cpp
$ a.out
(6.12132,3.70711)
Question 4.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
complex c1(4.0,3.0);
7.
cout
- c1: (4,3)(7.65844,6.40819)
- c1: (4,3)(7,6)
- both a & b
- None of the mentioned
Explanation:-
Answer: Option A. -> c1: (4,3)(7.65844,6.40819)We are adding the two complex numbers and printing the result.
Output:
$ g++ comp3.cpp
$ a.out
c1: (4,3)(7.65844,6.40819)
Question 5.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
complex i(2, 3);
7.
i = i * 6 / 3;
8.
cout
- (4, 6)
- (2, 3)
- (6, 12)
- None of the mentioned
Explanation:-
Answer: Option A. -> (4, 6)We are multiplying the complex number by 2.
Output:
$ g++ comp2.cpp
$ a.out
(4,6)
Question 6.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
complex c_double(2, 3);
7.
complex c_int(4, 5);
8.
c_double *= 2;
9.
c_double = c_int;
10.
cout
- (2, 3)
- (4, 5)
- (8, 15)
- None of the mentioned
Explanation:-
Answer: Option B. -> (4, 5)We are just copying the value of c_int into c_double, So it’s printing as (4,5).
Output:
$ g++ comp1.cpp
$ a.out
(4,5)
Explanation:-
Answer: Option C. -> 3There are three real types in complex numbers. They are float complex, double complex, long
double complex.
Question 8.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
complex c1(4.0, 16.0), c2;
7.
c2 = pow(c1, 2.0);
8.
cout
- (-240, 128)
- (240, 128)
- (240, 120)
- None of the mentioned
Explanation:-
Answer: Option A. -> (-240, 128)In this program, we are finding the square of the complex number.
Output:
$ g++ comp.cpp
$ a.out
(-240,128)
Explanation:-
Answer: Option A. -> complexnumNone.
Explanation:-
Answer: Option B. -> complex(3,4)We can declare the complex number by using complex(3,4) where 3 is a real number and
4 is imaginary part.