Monday, February 8, 2016

// Program to Swap Two Numbers Using Function Template. 

#include <iostream>
#include<conio.h>>
using namespace std;
template <class T>
void Swap(T &n1, T &n2)
{
    T temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}

int main()
{
    int i1=8, i2=2;
    float f1=7.1, f2=5.2;
    char c1='I', c2='T';
    cout<<"Before Swaping data to function template."<<endl;
    cout<<"i1 = "<<i1<<"\ni2="<<i2;
    Swap(i1, i2);
    cout<<endl<<"After swaping data to function template."<<endl;
    cout<<"i1 = "<<i1<<"\ni2="<<i2;

    cout<<endl<<"Before swaping data to function template."<<endl;
    cout<<"\nf1 = "<<f1<<"\nf2="<<f2;
    Swap(f1, f2);
    cout<<endl<<"After swaping data to function template."<<endl;
    cout<<"\nf1 = "<<f1<<"\nf2="<<f2;

    cout<<endl<<"Before swaping data to function template."<<endl;
    cout<<"\nc1 = "<<c1<<"\nc2="<<c2;
    Swap(c1, c2);
    cout<<endl<<"After swaping data to function template."<<endl;
    cout<<"\nc1 = "<<c1<<"\nc2="<<c2;
    getch();
    return 0;
}


OutPut
 


0 comments:

Post a Comment

Translate

Sample Text

Powered by Blogger.

Every thing is possible in real world....

Contact us

Name

Email *

Message *

IT Support

Blogroll

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Video

Our Facebook Page

Popular Posts

Total Pageviews