Sunday, March 17, 2013

Swapping Two Numbers

#include<iostream>
using namespace std;
int swap(int,int);
int main()
{
    int num1,num2;
    cout<<"Enter num1:";
    cin>>num1;
    cout<<"Enter num2:";
    cin>>num2;
    swap(num1,num2);
    cout<<"\n\n";
    cout<<"num1: "<<num1<<"\t"<<"num2: "<<num2;
    return 0;
}
int swap(int a,int b)
{
    int temp=a;
    a=b;
    b=temp;
    cout<<"Swaped nos. are:"<<a<<"\t"<<b;
}

0 comments:

Post a Comment