codescracker


c++

C++ Program to Interchange the Numbers



« Previous Program Next Program »


Interchange Numbers in C++

To interchange the numbers in C++ programming, you have to ask to enter the two number to interchange both the number. To interchange the number, make a variable say temp of same type which will help you in interchanging the numbers. Now to interchange the number, place the first number to temp, then place second number to the first and place temp to second as shown here in the following program.

C++ Programming Code to Interchange Numbers

Following C++ program ask to the user to enter two number (value of A and B) to interchange and display the result on the screen:

/* C++ Program - Interchange Numbers */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int a, b, temp;
	cout<<"Enter value of A and B : \n";
	cout<<"A = ";
	cin>>a;
	cout<<"B = ";
	cin>>b;
	temp=a;
	a=b;
	b=temp;
	cout<<"Number interchanged successfully..!!\n";
	cout<<"A = "<<a<<"\n"<<"B = "<<b;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program to interchange numbers

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test