Following Program Swap Two Numbers Using Function Template:
#include<iostream>
using namespace std;
template<class T>
void swapp(T &x,T &y)
{
T a;
a=x;
x=y;
y=a;
}
main()
{
int a,b;
cout<<"Enter A ";
cin>>a;
cout<<"Enter B ";
cin>>b;
swapp(a,b);
cout<<"\nAfter Swapping";
cout<<"\nA="<<a;
cout<<"\nB="<<b;
}
Output:
#include<iostream>
using namespace std;
template<class T>
void swapp(T &x,T &y)
{
T a;
a=x;
x=y;
y=a;
}
main()
{
int a,b;
cout<<"Enter A ";
cin>>a;
cout<<"Enter B ";
cin>>b;
swapp(a,b);
cout<<"\nAfter Swapping";
cout<<"\nA="<<a;
cout<<"\nB="<<b;
}
Output: