asked 218k views
3 votes
Show how to declare a tag namedcomplex for a structure with two members,real andimaginary, of type double.

1 Answer

2 votes

Answer:

#include <iostream>

using namespace std;

struct complex{ //Structure of name complex..

double real;//real part of type double..

double imaginary;//imaginary part of type double..

};

int main() {

complex n2; //object of structure complex..

n2.real=2.1;//assigining 2.1 to the real part..

n2.imaginary=5.6;//assigning 5.6 to the imaginary part..

cout<<n2.real<<" + "<<n2.imaginary<<"i"<<endl;//printing the complex number..

return 0;

}

Output:-

2.1 + 5.6i

Step-by-step explanation:

Declaring an object of structure complex name n2. Assigning 2.1 to the real part and 5.6 to the imaginary part.Then after that printing the output.

answered
User Dbanas
by
7.9k points