2
Answers

C# programming

manuel joseph

manuel joseph

12y
1.3k
1
Hi,

Write an algorithm to swap the values of two variables without using a third variable.
Answers (2)
0
Vulpes

Vulpes

NA 98.3k 1.5m 12y
Here's another way of doing it:

      int i = 1;
      int j = 2;
      i ^= j;
      j ^= i;
      i ^= j;
      Console.WriteLine("i = {0}, j = {1}", i, j);
0
Suthish Nair

Suthish Nair

NA 31.7k 4.6m 12y

  Something like this, try it..

            int i = 1;
            int j = 2;

            Console.WriteLine("i = " + i);
            Console.WriteLine("j = " + j);

            i = (j + i);
            j = (i - j);
            i = (i - j);

            Console.WriteLine("");
            Console.WriteLine("i = " + i);
            Console.WriteLine("j = " + j);
            Console.ReadKey();