Two numbers are taken from user and then swapped without using a third variable.
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int a,b;
- cout<<"Enter a: ";
- cin>>a;
- cout<<"Enter b: ";
- cin>>b;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- cout<<"Before swapping:"<<endl;
- cout<<"a: "<<a<<" b: "<<b<<endl;
- a=a+b;
- b=a-b;
- a=a-b;
- cout<<"After swapping:"<<endl;
- cout<<"a: "<<a<<" b: "<<b;
- getch();
- }
0 comments:
Post a Comment