Answer to Question #191202 in C++ for Mogera

Question #191202

write a program to pass two numbers as parameters to a function which is used to swap the two 

numbers.


1
Expert's answer
2021-05-10T03:15:34-0400
#include <iostream>
using namespace std;
 
void Swap(int a, int b)
{
	int temp = a;
	a = b;
	b = temp;
	cout << "a in Swap: " << a << endl;
	cout << "b in Swap: " << b << endl;
}
 
int main()
{
	int a, b;
	cout << "Enter a: ";
	cin >> a;
	cout << "Enter b: ";
	cin >> b;
	cout << "a in main: " << a << endl;
	cout << "b in main: " << b << endl;
	cout << endl << "Call Swap!" << endl;
	Swap(a, b);
	cout << endl;
	cout << "Back in main." << endl; 
	cout << "a in main: " << a << endl;
	cout << "b in main: " << b << endl;
	system("pause");
	return 0;
}

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