Two numbers are taken from the user and then swapped 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,c;
- cout<<"Enter a: ";
- cin>>a;
- cout<<"Enter b: ";
- cin>>b;
- cout<<"Before swapping:"<<endl;
- cout<<"a: "<<a<<" b: "<<b<<endl;
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- c=a;
- a=b;
- b=c;
- cout<<"After swapping:"<<endl;
- cout<<"a: "<<a<<" b: "<<b;
- getch();
- }
1 comments:
Have you checked this Write a program to Swap two variables or number.One can find almost all the methods of swapping of two numbers.
Post a Comment