C++ Program to Swap to integer value.This program asks user to enter two numbers and this program will swap the value of these two numbers.
Simply use oh three variable as shown in the program a, b & temp.
external variable temp is use to hold the value of a so that it can be use to assign value to b variable.
Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b,temp=0;
cout<<"Program to swap two number by-Tarun Rawat\n\n";
cout<<"Enter first number (let a) : ";
cin>>a;
cout<<"\nEnter second number (let b) : ";
cin>>b;
temp=a;
a=b;
b=temp;
cout<<"\nAfter swap :- ";
cout<<"\n\t\tValue of a is : "<<a<<"\n\n\t\tValue of b is : "<<b;
getch();
}
No comments:
Post a Comment