Ahmar Husain
Swap two numbers without using any third variable and arithmetic operator.
By Ahmar Husain in C# on Nov 25 2013
  • kamar rahi
    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
  • anusha raju
    Aug, 2015 18

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

    • 1
  • Aman Rohilla
    Mar, 2017 22

    Not get

    • 0
  • Devinder Kumar
    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
  • Rahul Prajapat
    Jun, 2015 1

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

    • 0
  • Pankaj  Kumar Choudhary
    Jun, 2015 1

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

    • 0
  • satish kumar
    May, 2015 23

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

    • 0
  • Sanjay Singh
    May, 2014 2

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

    • 0
  • Praveen Sinha
    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
  • Ahmar Husain
    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);
                Console.ReadLine();

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS