Swap/interchange variable c++ program question.
Asked By
30 points
N/A
Posted on - 04/03/2012
How can we right a program in which we swap/interchange just two integers, remember that we use only two variables?
How can we right a program in which we swap/interchange just two integers, remember that we use only two variables?
Â
Hi Bubble Jade,
Please find the below code to interchange / swap two variables in c++.
#include <iostream.h>
int main()
{
int a=3,b=4;
count<<" n Original value of a = "<<a<<" t b = "<<b;
a = a + b;
b = a – b;
a = a – b;
count<<" n Interchange value of a = "<<a<<" t b = "<<b;
return 0;
}
Thanks,
Sophia Taj
I've tried your program Sophia in interchanging two variables and looks like you've got it. Thanks! Very helpful indeed.
Thanks Sophia and techyv.