C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Swap two numbers using third variables Swap two numbers using third variables Swap numbers means exchange the values of two variables with each other. For example variable num1 contains 20 and num2 contains 40 after swap there values num1 contains 40 and num2 contains 20. Example: Suppose we have three glass A, B, Temp. Glass A contain 30, Glass B contain 50 and Glass Temp is empty now we want to interchange these two glass (A, B) valuse. So we follow below steps... #include<iostream.h> #include<conio.h> void main() { int a,b,c; clrscr(); cout<<"Enter value of a: "; cin>>a; cout<<"Enter value of b: "; cin>>b; c=a; a=b; b=c; cout<<"After swap a: "<<a<<"b: "<<b; getch(); }