The document is a C++ program that swaps the values of two integers a and b without using a third variable. It prompts the user to input values for a and b, displays their initial values, then performs the swap by adding a and b, subtracting that sum from a to get the original b value, and subtracting b from the sum to get the original a value, and finally displays the swapped values of a and b.
The document is a C++ program that swaps the values of two integers a and b without using a third variable. It prompts the user to input values for a and b, displays their initial values, then performs the swap by adding a and b, subtracting that sum from a to get the original b value, and subtracting b from the sum to get the original a value, and finally displays the swapped values of a and b.
The document is a C++ program that swaps the values of two integers a and b without using a third variable. It prompts the user to input values for a and b, displays their initial values, then performs the swap by adding a and b, subtracting that sum from a to get the original b value, and subtracting b from the sum to get the original a value, and finally displays the swapped values of a and b.
Write a program to swap to numbers without third variable.
#include<iostream> usingnamespacestd;
intmain() { int a, b; cin>> a >> b;
cout<<"The value of a before swap: "<< a <<endl;
cout<<"The value of b before swap: "<< b <<endl; a = a + b; b = a - b; a = a - b; cout<<"The value of a after swap: "<< a <<endl; cout<<"The value of b after swap: "<< b <<endl; return0; }