how to swap all the values without using temporary variable.
tha values r a = 20, x=60 and p=2.

Answers were Sorted based on User's Feedback



how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2. ..

Answer / learning

x=x-a;
a=x+a;
x=a-x;

x=x-p;
p=x+p;
x=p-x;

Is This Answer Correct ?    12 Yes 1 No

how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2. ..

Answer / gurusaran

x=x*a; (x=1200)
a=x/a; (a=60)
x=x/a; (x=20)

p=p*x; (p=40)
x=p/x; (x=2)
p=p/x; (p=20)

Hence final values are a=60,x=2,p=20

Is This Answer Correct ?    3 Yes 1 No

how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2. ..

Answer / padmas

To swap the values without using temporary variable
for a,x and p,
Do a call to swap function for a and p and
another call to same swap function for x and p.
call1:swap(a,p);
call2:swap(x,p);
swap(variable1,variable2)
{no temporary variable}

Is This Answer Correct ?    2 Yes 1 No

how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2. ..

Answer / chaitanya

x=x^a;
a=x^a;
x=a^x;

x=x^p;
p=x^p;
x=p^x;

Is This Answer Correct ?    2 Yes 3 No

how to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2. ..

Answer / padmas

If the values for a=20,x=60, and p=2 then
need another set of values for b=,y= and q= to do the swap
without using temporary variable.

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More Programming Languages AllOther Interview Questions

Why we use NEW operator when we create Object,While in C++ we donot ?

1 Answers  


Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance

0 Answers  


what is class module in vb6? what it's use? with example..

0 Answers  


Difference of Console, web & windows applications?

0 Answers  


how to convert the data from HTML file to SAS dataset?

0 Answers   Accenture,






what is difference between restoring and non restoring division?

2 Answers   Texas,


code for connection from windows forms to sql server

0 Answers   ME,


How to connect to ms word wit VB ojective is to prepare s/w to generate question paper , selects questions randomly from the ms access , database

0 Answers   Wipro,


the systematic access of small computers in a distributed data processing system is referred as?

0 Answers   Mphasis,


Can i please VHDL code for D-Latch with clear input ?? (HINT: Set up a “Process” with appropriate sensitivity list to get the desired D-Latch with Clr working.) Inputs and Outputs: entity Lab4b is Port ( Clr, Clk, D : in STD_LOGIC; Q : out STD_LOGIC); end Lab4b;

0 Answers  


Write a program to implement BFS/ DFS routine in a connected graph

1 Answers  


what is the extension of SPDS Dynamic cluster tables?

0 Answers   IBM,


Categories