Skip to main content

Swap two numbers without using third variable

Swap two numbers without using third variable.


   A = B / A       (now, A will have value val b/ val a and B will have value val b)
   B =  B / A       (now, A will have value val b/ val a and B will have value val a)
   A = A * B       (now, A will have value val b  and B will have value val a)
Above method overflow should be take care

   A = A + B;
   B = A – B;
   A = A – B;

   A = A ^ B;
   B = A ^ B;
   A = A ^ B;

Comments

Popular posts from this blog

CAN INTERVIEW QUESTIONS

Qualifiers and Modifier in C

RTOS Real time operating system interview questions

CAN INTERVIEW QUESTIONS 2

What is UDS protocol

Memory mapping in c

TOP IOT PLATFORMS