9
Reply

Swap two numbers without using any third variable and arithmetic operator.

Ahmar Husain

Ahmar Husain

Nov 25, 2013
8.8k
0

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

    anusha raju
    August 18, 2015
    1

    Not get

    Aman Rohilla
    March 22, 2017
    0

    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

    Dev sharma
    July 08, 2015
    0

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

    Rahul Prajapat
    June 01, 2015
    0

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

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

    satish kumar
    May 23, 2015
    0

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

    Sanjay Singh
    May 02, 2014
    0

    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();}} }

    Praveen Sinha
    May 01, 2014
    0

    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);
                Console.ReadLine();

    Ahmar Husain
    November 25, 2013
    0