Wednesday 2 May 2012

No third variables and pointers-C++ swapping program


#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
    int a,b;
    cout<<"Enter two number:\t";
    cin>>a>>b;
    cout<<"\nBefore swapping:\t";
    cout<<a<<"\t"<<b;
   
    a=a+b;
    b=a-b;
    a=a-b;
    cout<<"\nAfter swapping:\t";
    cout<<"\t"<<a<<"\t"<<b;
    getch();
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More