English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

only 2 variable can be swapped
temp = x
x=y
y=temp

2007-03-16 22:56:31 · answer #1 · answered by Anonymous · 0 0

i hope your ques shud be a bit clear. If you want to swap three variable you have to mention the places of the three variables. Or else there will totally 6 possibilities with three variables.

2007-03-17 05:59:08 · answer #2 · answered by uday's 1 · 0 0

It's impossible to swap 3 variables!
x, y and z
"x" takes the value "y" and "y" takes the value of "x"; which value should "z" take then?!
Swapping means a bi-directional exchange of values between two variables.
if x takes the value of y and y takes the value of x, z takes the value of nothing
if x takes the value of z and z takes the value of x, y takes the value of nothing
if y takes the value of z and z takes the value of y, x takes the value of nothing
You see ... There will always be one variable that takes nothing!
It's impossible

2007-03-17 10:37:32 · answer #3 · answered by Coosa 2 · 0 0

#include
using namespace std;
main()
{
int x,y ;

system("cls");
cout <<"\n\tInterchange x and y using only two variables";
cout << "\n\tand using three mathematical statements.\n";
cout << "\n\tEnter the value of x and y :";
cin >> x >> y;
x=x+y;
y=x-y;
x=x-y ;
cout << "\n\tx= " << x << "\t\ty= " << y << "\n\n";
system("pause");

}

2007-03-17 05:43:25 · answer #4 · answered by iyiogrenci 6 · 0 1

fedest.com, questions and answers