0% found this document useful (0 votes)
6 views2 pages

Exp 1

Bebbd

Uploaded by

amanpache2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Exp 1

Bebbd

Uploaded by

amanpache2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// program for complex constructor to add two complex number.

Program:

#include <iostream.h>

#include<conio.h>

class complex

public :

int real, img;

};

void main( )

complex a, b, c;

cout << "Enter a and b where a + ib is the first complex number.";

cout << "\na = ";

cin >> a.real;

cout << "b = ";

cin >> a.img;

cout << "Enter c and d where c + id is the second complex number.";

cout << "\nc = ";

cin >> b.real;

cout << "d = ";

cin >> b.img;

c.real = a.real + b.real;

c.img = a.img + b.img;

if ( c.img >= 0 )

cout << "Sum of two complex numbers = " << c.real << " + " << c.img << "i";

else

cout << "Sum of two complex numbers = " << c.real << " " << c.img << "i";
getch( );

*******************************************************************************************

Output:

enter a & b where a+ib is the first complex number

a =2

b =3

enter c & d where c+ib is the second complex number

c=3

d =2

sum of two complex number is = 5+5i

You might also like