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 limitation in using querystring in .net?

1 Answers   Tesco,


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

0 Answers  


Fortran cannot have value by reference True or False?

2 Answers   Geometric Software,


In Java what is the difference between following two statements ? int a[],b; int []a,b;

1 Answers  


what do u mean by tagging

0 Answers  






Crystal report proffessional 9 to filter the issue date!!

1 Answers  


How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there

0 Answers   247Customer,


hai i am mca 2009 fresher.please tell me which certification helps me to get an IT job faster which institute is good in hyderabad.please mail me to prasanna.1856@rediff.com

0 Answers  


what is the use MDM(Master Data Management)and meaning

0 Answers  


how to display xisheet in list box in c# .net

0 Answers  


Data Structure: Show that if k is the smallest integer greater than or equal to n+ (log2n)-2, k comparisons are necessary and sufficient to find the largest and second largest elements of a set of n distinct elements. (k comparisons are required to find what you are looking for, but no more than that are needed)

0 Answers   Student,


if we want to move all the items that are already added in a combobox into an empty list box or vice-versa then how can it possible in vb or C# ?

1 Answers  


Categories