WAP in C++ for Swapping

Write a function in C++ that exchanges data (passing by reference) using a swap function to interchange the given two numbers.

#include<iostream.h>
#include<conio.h>
void swap(float& x, float& y)
{
	float t = x;
	x = y;
	y = t;
}
void main()
{
	void swap(float&, float&);
	float a, b;
	cin >> a >> b;
	cout << "a=" << a << "b=" << b << endl;
	swap(a, b);
	cout << "a=" << a << "b=" << b << endl;
	getch();

}

Leave a Comment

Scroll to Top