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

What are the Advantages of HashMap over Vector?

1 Answers  


what is web configuration file

0 Answers   HCL,


Difference between views and index in sas programming

0 Answers   Ventois,


What is std::auto_ptr?

1 Answers   Amazon,


What binary value will be internally stored for NULL for the type S9(1) COMP 3 in mainframe

0 Answers  






Mainly Related to Oracle, DBMS , Oracle Stored Procedures, Functions, Oracle 9i Architecture, Redo logs..., Views,

0 Answers   Indian Overseas Bank,


What is autocall macro and how to create autocall macro? what is the use of it?

0 Answers   GE,


What language / script is used to validate web page

3 Answers  


how we can know the funcions available in a class recording java?

0 Answers  


How to rename A1-A30 datasets into B1-B30 using macros?

1 Answers   Icon,


how can i create report in abap to insert data in table pa0002 using insert command

0 Answers  


preorder of A*(B+C)/D-G

6 Answers   BFL,


Categories