Swap two numbers without using any third variable and arithmetic operator.
By in on Nov 25 2013
• Apr, 2018 13

int a=1; int b=2;a=a b; b=a-b; a= a-b;console.writeline(a.tostring()); console.writeline(b.tostring()); console.readline();Result : 2 1

• 1
• Aug, 2015 18

int a=10; int b=2; a=a^b; b=a^b; a=a^b;

• 1
• Mar, 2017 22

Not get

• 0
• Jul, 2015 8

int a =10;int b=20;a = a + b; /// a=30,b=20b = a - b; /// b=10,a=30a = a - b; /// a=20,b=10

• 0
• Jun, 2015 1

i=10; j=20; i = i ^ k; k = i ^ k; i = i ^ k;

• 0
• Jun, 2015 1

i=10; j=20; i = i ^ k; k = i ^ k; i = i ^ k;

• 0
• May, 2015 23

int a =10,int b=20;a= a b;b= a-b;a= a-b;

• 0
• May, 2014 2

x = x * y; y = x / y; x = x / y;

• 0
• May, 2014 1

using System;namespace SwapTwoNoWithoutUsing3rdVarArithOperator {class Program{static void Main(string[] args){int i = 65; int k = 120; Console.WriteLine("The value of i={0} and j={1} before swapping" ,i,k);i = i ^ k; k = i ^ k; i = i ^ k;Console.WriteLine("The value of i={0} and j={1} after swapping", i, k);Console.ReadLine();}} }

• 0
• Nov, 2013 25

The solution is two use XOR operator
int Fisrt = 221;
int Second = 100;
Fisrt = Fisrt ^ Second;
Second = Fisrt ^ Second;
Fisrt = Fisrt ^ Second;
Console.WriteLine(Fisrt);
Console.WriteLine(Second);