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

What is the use of endl?

539


Must accepts "Maestro Cards" Tax for bike should be less than 15 Total number of lanes is more than 10 Must provides monthly pass Write a method: boolean isGoodTollBridge(String[] cardsAccepted, String[] tollTax, boolean hasMonthlyPass, int numberOfLanes); String[] cardsAccepted A String array of names of card types accepted for payment of toll tax, it can be null if the toll does not accept any card String[] tollTax A String array of toll tax chart (say “Train : 300”,”BullCart : 10”) boolean hasMonthlyPass This parameter defines whether there is any monthly pass available or not int numberOfLanes This parameter defines the number of lanes for each side

3042


Write is a binary search tree? Write an algo and tell complexity?

587


How can you say that a template is better than a base class?

578


Explain the difference between overloading and overriding?

605






Is string data type in c++?

579


Is c++ still being used?

558


. If employee B is the boss of A and C is the boss of B and D is the boss of C and E is the boss of D. Then write a program using the Database such that if an employee name is Asked to Display it also display his bosses with his name. For eg. If C is displayed it should also display D and E with C?

2750


Differentiate between a constructor and a method in C++.

552


What it is and how it might be called (2 methods).

654


Explain deep copy?

602


What is ostream in c++?

567


How do you declare a set in c++?

528


Can a program run without main function?

611


If a base class is an adt, and it has three pure virtual functions, how many of these functions must be overridden in its derived classes?

586