answersLogoWhite

0

If the variables are x1 & x2

the solution is :

1) x1=x1+x2;

2) x2=x1-x2;

3) x1=x1-x2;

EX: x1=1 , x2=6;

1) x1= 1+6 = 7

2) x2= 7-6 =1

3 x1=7-1 =6

============================================

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

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 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)


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

a=a^b; b=a^b; a=a^b;


How do you swap variables in PHP?

By using a third temporary variable. $tmp = $a; $a = $b; $b = $tmp;


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;


How do yow swap two variables in java using a function?

You can swap two variables, by storing one of them temporarily in a third variable, like this: temp = a; a = b; b = temp; Inside a function, this won't work, because the function parameters are COPIES of the original variables, not the variables themselves. Any change won't affect the original variables. If you work with OBJECTS, and swap the CONTENTS of the objects (not the object pointers), it can work, though.


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.


Swapping of 2 numbers using java language?

Use a temporary variable. Example (swap variables "a" and "b"): int a = 5; int b = 10; // Swap the variables int temp; temp = a; a = b; b = temp; System.out.println("a = " + a); System.out.println("b = " + b);Use a temporary variable. Example (swap variables "a" and "b"): int a = 5; int b = 10; // Swap the variables int temp; temp = a; a = b; b = temp; System.out.println("a = " + a); System.out.println("b = " + b);Use a temporary variable. Example (swap variables "a" and "b"): int a = 5; int b = 10; // Swap the variables int temp; temp = a; a = b; b = temp; System.out.println("a = " + a); System.out.println("b = " + b);Use a temporary variable. Example (swap variables "a" and "b"): int a = 5; int b = 10; // Swap the variables int temp; temp = a; a = b; b = temp; System.out.println("a = " + a); System.out.println("b = " + b);


Swap logic without using third variable?

a ^= b; b ^= a; a ^= b;


What is program in c to swap entered two numbers without using third variable?

The required c program is given below /*Swapping(interchange) the two entered numbers*/ #include<stdio.h> main() { /*Without using third variable*/ int a,b,t; printf("Enter a:"); scanf("%d",&a); printf("Enter b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("\n After swapping without using third variable"); printf("\na=%d\nb=%d",a,b); }


Swapping without third variable?

There are two ways in which you can swap without a third variable. 1. Using xor operation swap( int *a, int *b) { *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b; } 2. Using addition and subtraction swap( int *a, int *b) { *a = *a + *b; *b = *a - *b; *a = *a - *b; } }


Swapping 2 variables just by using those two variables?

Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is: Just use a third variable and do a standard swap: Thing first = ... Thing second = ... Thing swap = first; first = second; second = swap; Is impossible without doing things you really shouldn't be doing. For example with strings you might try concatenating them together and splitting it back apart to accomplish a swap, or with integers you might be able to use math to do this. None of these techniques will generalize to an arbitrary data type, however, so my recommendation is: Just use a third variable and do a standard swap: Thing first = ... Thing second = ... Thing swap = first; first = second; second = swap;