You Have to write aprogram in C++ in which we interchange the value of two varia
ID: 3608710 • Letter: Y
Question
You Have to write aprogram in C++ in which we interchange the value of two variableswithout using a third variable? the first thing comes in ur mindwill be the technique of swaping but swaping works with a temporaryvariable....here i mention that we do not hav permission to declarea 3rd variable...... You Have to write aprogram in C++ in which we interchange the value of two variableswithout using a third variable? the first thing comes in ur mindwill be the technique of swaping but swaping works with a temporaryvariable....here i mention that we do not hav permission to declarea 3rd variable......Explanation / Answer
#include <iostream>
using namespace std;
int main() { int a = 5, b = 23; cout << "a is originally: " <<a << endl; cout << "b is originally: " <<b << endl; a += b; b = a-b; a = a-b; cout << "a after the swap: " <<a << endl; cout << "b after the swap: " <<b << endl; system("pause"); return 0; }
#include <iostream>
using namespace std;
int main() { int a = 5, b = 23; cout << "a is originally: " <<a << endl; cout << "b is originally: " <<b << endl; a += b; b = a-b; a = a-b; cout << "a after the swap: " <<a << endl; cout << "b after the swap: " <<b << endl; system("pause"); return 0; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.