Write a C++ Program to Swap Two Numbers without using third variable. C++ Program to Swap Two Numbers without third variable. Here’s simple Program to Swap Two Numbers without using temp variable in C++ Programming Language.
Here is source code of the C++ Program to Swap Two Numbers without using third variable. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
/* C++ Program to Swap Two Numbers without using third variable */
#include <iostream>
using namespace std;
int main()
{
int a,b ;
cout<<"Enter 1st number :: ";
cin>>a;
cout<<"\nEnter 2nd number :: ";
cin>>b;
cout << "\nBefore swapping, Numbers are :: " << endl;
cout << "\n\ta = " << a << ", b = " << b << endl;
a = a + b;
b = a - b;
a = a - b;
cout << "\nAfter swapping, Numbers are :: " << endl;
cout << "\n\ta = " << a << ", b = " << b << endl;
return 0;
}
Output : :
/* C++ Program to Swap Two Numbers without using third variable */
Enter 1st number :: 5
Enter 2nd number :: 9
Before swapping, Numbers are ::
a = 5, b = 9
After swapping, Numbers are ::
a = 9, b = 5
Process returned 0
Above is the source code for C++ Program to Swap Two Numbers without using third variable which is successfully compiled and run on Windows System.The Output of the program is shown above .
Here is source code of the C++ Program to Swap Two Numbers without using third variable. The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.
SOURCE CODE : :
Output : :
Above is the source code for C++ Program to Swap Two Numbers without using third variable which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer