Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct complex{
- int real ;
- int imag ;
- } complex1, complex2, temp ;
- void swap_complex (complex*, complex* ) ;
- int main()
- {
- cout << "Enter real and imaginary part of a complex number :" ;
- cin >> complex1.real >> complex1.imag ;
- cout << "\nEnter real and imaginary part of another complex number :" ;
- cin >> complex2.real >> complex2.imag ;
- cout << "\n\n--------Before Swapping---------"<<endl;
- cout << "\nFirst complex number : "<<complex1.real<<"+"<<(complex1.imag)<<"i" ;
- cout << "\nSecond complex number : "<<complex2.real<<"+"<<(complex2.imag)<<"i" ;
- swap_complex(&complex1, &complex2);
- cout << "\n\n--------After Swapping---------"<<endl;
- cout << "\nFirst complex number : "<<complex1.real<<"+"<<(complex1.imag)<<"i" ;
- cout << "\nSecond complex number : "<<complex2.real<<"+"<<(complex2.imag)<<"i\n\n" ;
- return 0;
- }
- void swap_complex (complex* a, complex* b )
- {
- temp.real = (*a).real; //for Pointer : using ' (*a) ' is equivalent to ' -> ' . Either of them can be used for pointing operation
- temp.imag = (*a).imag ;
- (*a).real = (*b).real ;
- (*a).imag = (*b).imag ;
- (*b).real = temp.real;
- (*b).imag = temp.imag ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement