answersLogoWhite

0

There are three primary algorithms to exchange the values of two variables.

Exchange with Temporary Variable

temp = a;

a = b;

b = temp;

Exchange Without Temporary Variable Using Exclusive Or

a = a ^ b;

b = b ^ a;

a = a ^ b;

Exchange Without Temporary Variable Using Arithmetic

a = a + b;

b = b - a;

a = a - b;

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
More answers

write a program in c swap two number without using tempry vriable with flochart and algorithum

User Avatar

Wiki User

11y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is the Algorithm for exchanging values of two variables?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write C coding for swamping the values of two variables without using a third variable?

I'll assume you meant to say: Swapping instead of Swamping. You would need to perform the XorSwap algorithm: void XorSwap(int *x, int *y) { if(x != y) { *x ^= *y; *y ^= *x; *x ^= *y; } } You can read more about this algorithm on Wikipedia.


A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string


Write a program that defines a template function named add This function takes two arguments add two variables and then return the sum?

Write a program that defines a template function named add(). This function takes two arguments, add two variables and then return the sum. In main function, define two variables of type int, two variables of type float and two objects of type 'String'. Now call the add() function three times for these different data types. Note: String is a user-defined data type and for this you have to define a class named 'String'. When template function will be called to add two objects of type String then it must concatenate two strings. Your output should look like this: Sample Output: Enter two integer values to be added Enter First value: 12 Enter Second value: 25 Enter two float values to be added Enter First value: 13.5 Enter Second value: 14.2 Enter two Strings to be added Enter First value: Virtual Enter Second value: University Addition of two variables of different data types Sum of values of type int = 37 Sum of values of type float = 27.7 Sum of values of type String = VirtualUniversity


What difference between two nodes in c plus plus of single link list?

Their address. They may also have different values, and their sequence may matter, depending on the design of the algorithm.


Program designed to swap the values of two variables?

You'll need 3 variables for this, here's a pseudo code for swapping values of 2 variables.ALGORITHM SWAPvar1 = 10var2 = 20temp = 0temp = var1 "temp = 10"var1 = var2 "var1 = 20, originally 10"var2 = temp "var2 = 10, originally 20"END SWAP