answersLogoWhite

0

x=9;

y=4;

x=x+y; #x=13;y=4;

y=x-y; #y=13-4=9;

x=x-y; #x=13-9=4;

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Write flowchart searching algorithm?

flow chart to swap two number


Java program to swap values of 2 variables?

a=a+b; b=a-b; a=a-b;


What is the Algorithm for exchanging values of two variables?

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;


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


How do you write an algorithm to swap the values of x and y using a temporary variable t?

To swap the values of two variables, x and y, using a temporary variable t: t = x; x = y; y = t; To implement this algorithm as a function, the variables must be passed by reference. For efficiency, particularly with large or complex objects that are expensive to copy, use move semantics. The C++ standard library provides the following implementation (since C++11): namespace std { template<typename T> void swap (T&& x, T&& y) { T t = std::move (x); x = std::move (y); y = std::move (t); } }; The C++ standard library swap function (std::swap) uses the above implementation (since C++11). If a type does not support the move semantic, copy semantics will be used instead.


How do you write a program in C to swap two variables using the third variable?

Consider the following declarations:int x = 0;int y = 1;In order to swap the values, we need to use a temporary variable:int t = x;x = y;y = t;However, it is possible to swap the values without using a third variable:x ^= y ^= x ^= y;


What is meant by swapping of variables?

It means that you swap the values of that variables EX: -==- before swapping :- Variable1 = 5; variable2 = 10; after swapping :- Variable1 = 10; variable2 = 5;


How do you write a program in Perl to swap two variables without using the third one?

Use list assignment i.e. for two variables $a, $b: ($a,$b) = ($b,$a)


Write a function using reference variables as arguments to swap the values of a pair of integers?

#include<iostream> using namespace std; void swap(int &i, int &j) { int temp = i; i = j; j = temp; } int main() { int i,j; cin>>i>>j; cout << i << j << endl; swap(i,j); cout << i << j; return 0; }


How do you write a javascript to swap two numbers without using third one?

By using the algorithm of bitwise EORing (Exclusive ORing) the numbers together:If the two numbers are X and Y, then to swap them:X = X EOR YY = Y EOR XX =X EOR Ywill swap them.With knowledge of that algorithm, one then uses the syntax of Javascript to implement it.


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


How do you swap the hieghest value n array with the lowest value give an algorithm for it?

To swap the highest and lowest values in an array, follow these steps: Initialize two variables, maxIndex and minIndex, to track the indices of the maximum and minimum values, respectively. Iterate through the array to find maxIndex (the index of the highest value) and minIndex (the index of the lowest value). Once both indices are found, swap the values at these indices. Here’s a simple pseudocode representation: function swapHighestLowest(arr): maxIndex = 0 minIndex = 0 for i from 1 to length(arr) - 1: if arr[i] > arr[maxIndex]: maxIndex = i if arr[i] < arr[minIndex]: minIndex = i swap(arr[maxIndex], arr[minIndex])