Thursday, January 19, 2023

ADDITION OF TWO COMPLEX NUMBER USING FRIEND FUNCTION

 #include<iostream>

using namespace std;


class complex

{

int a,b;

public:

complex()

{

}

complex(int x,int y)

{

a=x;

b=y;

}

void display()

{

if(b>0)

{

cout<<a<<"+i"<<b<<endl;

}

else

{

cout<<a<<"-i"<<b<<endl;

}

}

friend void add(complex,complex);

};

void add(complex ob1, complex ob2)

{

complex ob3;

ob3.a=ob1.a+ob2.a;

ob3.b=ob1.b+ob2.b;

ob3.display();

}


int main()

{

complex ob1(2,-3),ob2(4,5);

add(ob1,ob2);

}

No comments:

Post a Comment

Complete Works of Swami Vivekananda [Volume 8,Page - 2069]

  Complete Works of Swami Vivekananda [ Volume 8, Page - 2069] Jesus Christ was God — the Personal God become man. He has manifested Himsel...