Swapping of two numbers without using third variable using dotnet with c sharp

Category > CSHARP || Published on : Sunday, August 14, 2016 || Views: 9912 || Swapping of two numbers without using third variable


Introduction

Here Pawan Kumar will explain how to do swapping of two numbers without using third variable using dotnet with c sharp

Description

In previous post I have explained Top Popular Open Source .Net Projects - Websites/Portals : Portal/CMS, Top Popular Open Source Forum ASP.Net Projects, Show Confirm Navigation using onbeforeunload event in javascript, MySQL Tutorial, Mvc 4 Razor CRUD Operation using C# || ASP.NET MVC 4 application to Create/Insert,Read,Update,Delete and Search functionality using Razor view engine and Entity Framework, Top Popular Open Source E-Commerce ASP.Net Projects, and many more articles.

Now I will explain How to Swapping of two numbers without using third variable using dotnet with c sharp

So follow the steps to learn Swapping of two numbers without using third variable using dotnet with c sharp
********************************************************************************
 //  SWAPPING OF TWO NUMBERS WITHOUT USING THIRD VARIABLE USING DOTNET WITH C SHARP
********************************************************************************


using System;
using System.Collections.Generic;
using System.Text;

namespace swap
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, num;

            Console.Write("Enter the first value : ");
            n = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter the Second value : ");
            num = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("\n\nValues Before Swapping ");
            Console.Write("\nFirst Value = " + n);
            Console.Write("\nSecond Value = " + num);

            n = n + num;
            Console.Write("\n value of n = n + num : " + n);
            num = n - num;
            Console.Write("\n value of num = n - num : " + num);
            n = n - num;
            Console.Write("\nFinally value of n = n - num : " + n);

            Console.WriteLine("\n\nLETS SEE VALUES AFTER SWAPPING : ");
            Console.Write("\nFirst value : " + n);
            Console.Write("\nSecond Value : " + num);

            Console.WriteLine("\nPress any key to exit");
            Console.ReadLine();


        }
    }
}

Output

Conclusion:

So, In this tutorial we have learned, Swapping of two numbers without using third variable using dotnet with c sharp