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

can we convert .class file to dll file

1 Answers  


List and explain any five built in functions for Lists data type in python

1 Answers   Peerless,


what is mutex?

4 Answers   Axiom, Blue Star, SQL Star,


7.x=10; y=20; x<<2=? x<<1=? y>>2=?

1 Answers  


I m new to the dbms. Recently i came across words clustered indexes & nonclustered indexes but i dont know what is this all about & whats the difference between them.. So please help me!!!!!!!!

0 Answers  


purpose of abstraction and interface

0 Answers  


Explain recursion with an example.

1 Answers  


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

0 Answers   Accenture,


what is microprocessor?

1 Answers   HCL,


how we can connect applet with database?

1 Answers  


why main() method should not return any value

2 Answers   Accenture,


THE CHANNEL IN DATA COMMUNICATION CAN BE?

0 Answers   TCS,


Categories