Friday, 1 December 2017

Csharp Swap two Numbers Bitwise XOR Operation


Code:

using System;
class program
{
    public static void Main()
    {
        int i, k;
        Console.WriteLine("Enter two integers \n");
        i = int.Parse(Console.ReadLine());
        k = int.Parse(Console.ReadLine());
        Console.WriteLine("\n Before swapping i= {0} and k = {1}", i, k);
        i = i ^ k;
        k = i ^ k;
        i = i ^ k;
        Console.WriteLine("\n After swapping i= {0} and k = {1}", i, k);
        Console.ReadLine();
    }
}


Output:

Enter two integers
23
34
Before swapping i= 23 and k = 34
After swapping i= 34 and k = 23


More C# Programs:


















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...