Answer to Question #172973 in C++ for Sivasurya G

Question #172973

The kids Ram and Anandh are using magic numbers. For example, Ram magic number is 4 and Anandh magic number is 6. The kids exchange their magic number and display the Ram magic number is 6 and Anandh magic number is 4. Implement the above logic using function. [Note: Use call by address]


1
Expert's answer
2021-03-18T12:48:57-0400
#include <iostream>


using namespace std;


void magicSwap(int &a, int &b);


int main()
{
	int ramMagicNumber = 0;
	cout << "Enter Ram magic number: ";
	cin >> ramMagicNumber;
	int anandhMagicNumber = 0;
	cout << "Enter Anandh magic number: ";
	cin >> anandhMagicNumber;
	cout << "Ram magic number is: " << ramMagicNumber << endl;
	cout << "Anandh magic number is: " << anandhMagicNumber << endl;
	cout << endl << "Call magicSwap funtion...." << endl << endl;
	magicSwap(ramMagicNumber, anandhMagicNumber);
	cout << "Now: " << endl;
	cout << "Ram magic number is: " << ramMagicNumber << endl;
	cout << "Anandh magic number is: " << anandhMagicNumber << endl;
	return 0;
}


void magicSwap(int &a, int &b)
{
	int temp = 0;
	temp = a;
	a = b;
	b = temp;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS