title: Swap using template
program:
#include<iostream>
using namespace std;
template<class T>
void swapme(T & x, T & y)
{
T temp = x;
x=y;
y=temp;
}
int main()
{
int a,b;
cout<<"Enter the two integer values : ";
cin>>a>>b;
swapme(a,b);
cout<<"After Sapping A ="<<a<<", B = "<<b<<endl;
double p,q;
cout<<"Enter the two double values :";
cin>>p>>q;
swapme(p,q);
cout<<"After the swapping : P ="<<p<<" , Q = "<<q<<endl;
return 0;
}
OUPUT
No comments:
Post a Comment