Swap two variable without using the third variable

using System;

namespace Swap
{
    class Program
    {
        private static void Main(string[] args)
        {
            int a = 1000;
            int b = 999;
            Console.WriteLine("Before Swap");
            Console.WriteLine("Value of A :{0} ", a);
            Console.WriteLine("Value of B :{0} ", b);
            a = a + b;
            b = a - b;
            a = a - b;
            Console.WriteLine("After Swap");
            Console.WriteLine("Value of A :{0} ", a);
            Console.WriteLine("Value of B :{0} ", b);
            Console.ReadLine();
        }

    }
}
Catch us on social media

Author Profile

Deependra Kushwah
Deependra Kushwah
Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Deependra Kushwah

Deependra is a Senior Developer with Microsoft technologies, currently working with Opteamix India business private solution. In My Free time, I write blogs and make technical youtube videos. Having the good understanding of Service-oriented architect, Designing microservices using domain driven design.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RSS
Facebook
Google+
https://betechnical.blog/2016/12/03/swap-two-variable-without-using-the-third-variable">
Twitter
YouTube
Pinterest
Pinterest
LinkedIn
Instagram
%d bloggers like this: