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

Given: coordinates of rectangle-> left bottom and right top points. the rectangles create a hole.Find the maximum area of the hole. eg. 4 rectangles create a hole in between. find its area.

0 Answers   Manhattan,


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

1 Answers  


Outline the two important features of a terminating recursion. Any ideas?

0 Answers  


What are scrubbing procedures in SAS

1 Answers   IBM,


what is difference between sap and java ?

1 Answers  






when will triggars the at new event in abap and web dybn pro?

0 Answers   TCS,


details description on this mantis? who is founder of this mantis?

0 Answers  


I've an application where i need to give access to all the features only to admin and only few features to normal users. Say Menu...i dont want all my menu items to be accessible to all the users only the admin people can see few all the features where as normal users can have access to limited menu items...how can i achieve this. Please note that my menu is not a database driven menu.

1 Answers   Tesco,


how we define two jobs have same name??is it exist??

0 Answers   CTS,


5. Which of the following can you do with DB2 Express- C? Query databases with SQL Query databases with XML using XQuery and XPath Use SQL in Xquery and Xquery in SQL All of the above

0 Answers  


What parameters are used to run a JCL JOB on a perticular DAY and TIME and DATE

1 Answers  


can we allocate memory for interface? if no then why?

0 Answers  


Categories