how to swap two numbers with out using temp variable

Answer Posted / vishal gupta

well, use math:

x=5;
y=7;
x = x * y;
y = x / y;
x = x / y;

And the numbers have been swapped without the use of an
extra variable. I hope it helped.

Is This Answer Correct ?    44 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there a sort function in c++?

543


What is virtual destructor? What is its use?

571


Why do we need constructors in c++?

606


What are the steps in the development cycle?

605


How c functions prevents rework and therefore saves the programers time as wel as length of the code ?

615






What is static class data?

569


What's the most powerful programming language?

580


Explain queue. How it can be implemented?

667


What is math h in c++?

602


what is pre-processor in C++?

587


How to implement is-a and has-a class relationships?

576


What are the advantages of using a pointer? Define the operators that can be used with a pointer.

597


Can you pass an array to a function in c++?

532


List the merits and demerits of declaring a nested class in C++?

599


When one must use recursion function? Mention what happens when recursion functions are declared inline?

637