write a program to swap two numbers using a third variable

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 :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a,b,c;
  7. cout<<"Enter a: ";
  8. cin>>a;
  9. cout<<"Enter b: ";
  10. cin>>b;
  11. cout<<"Before swapping:"<<endl;
  12. cout<<"a: "<<a<<" b: "<<b<<endl;
  13. //Coding by: Snehil Khanor
  14. //http://WapCPP.blogspot.com
  15. c=a;
  16. a=b;
  17. b=c;
  18. cout<<"After swapping:"<<endl;
  19. cout<<"a: "<<a<<" b: "<<b;
  20. getch();
  21. }

Check out this stream