Thursday, January 19, 2023

SUBTRACTION 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

Interference in Light vs Quantum States

🔬 The Double-Slit Experiment: Where It All Begins One of the most famous demonstrations of interference is the double-slit experiment. When...