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

SD Card vs SSD: What’s Really Happening Inside Your Storage

  We use SD cards in phones and cameras, and SSDs in laptops and PCs, almost without thinking. They both feel similar—fast, silent, and com...