Write a Program to Swap Two Number.
Working
- Make Three Variable First,Second and Temporary.
- Get Value from user.
- Display Number Before Swap
- Move First Number to Temporary ( Temp = First )
- Move Second Number to First Number ( First = Second )
- Move Temporary to Second Number ( Second = Temp )
- Display Number After Swap
Program
//Swap Two Number in CPP #include<iostream.h> #include<conio.h> void main(){ clrscr(); int first_num,second_num,temp=0; cout<<"\n Swap Two Number "; cout<<"\n -------------------------------- "; cout<<"\n Enter the First Number : "; cin>>first_num; cout<<"\n Enter the Second Number : "; cin>>second_num; //Before Swap cout<<"\n Before Swap First Number : "<<first_num<<" Second Number : "<<second_num; //Swap Process temp = first_num; first_num = second_num; second_num = temp; //after Swap cout<<"\n After Swap First Number : "<<first_num<<" Second Number : "<<second_num; getch(); }
(Visited 154 times, 1 visits today)