write a program to swap two numbers



The code for this program is as follows:

#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();
}

#include<iostream.h> used for input/output of data
#include<conio.h> provides several functions like clrscr(), getch() etc.
After that in main() function we have declared a variables a, b, c; after that we have used clrscr(); function to clear the scree when program will run. It will clear the previous output from any program. Now we have used the cout function that shows message “Enter value of a:”; and when we enter any number then this number is read by cin function and assign to a variable. Now we have used the cout function that shows message “Enter value of b:”; and when we enter any number then this number is read by cin function and assign to b variable. Now we have to assign the value of a to c, b to a and c to b after that we get the swapped number,
the output is as follows:

c++ program