"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to swap two numbers in c++ with using third variable. We will use three variable for swapping the numbers. In this program we are assigning the default value to variable.
Swapping mean interchange of the values.
Let’s suppose a user will input two number as a ‘50’ and ‘30’ then we will perform swapping operation on it. We will swap the numbers with the help of third variables.
#include<iostream.h> #include<conio.h> //SWAP OF TWO NUMBER PROGRAM USING THIRDVARIABLES void main() { int num = 50, num1 = 30, swap; clrscr(); cout<<"BEFORE SWAPPING OF TWO NUMBER :- "<<num<<" "<<num1; swap = num; num = num1; num1 = swap; cout<<"\nAFTER SWAPPING OF TWO NUMBER :- "<<num<<" "<<num1; getch(); }
BEFORE SWAPING OF TWO NUMBER :- 50 30 AFTER SWAPING OF TWO NUMBER :- 30 50