Swapping of two number program in C# without using third variable

A simple program of swapping of two number without using 3rd variable in C#.

Program of swapping two numbers in c# without using third variable


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

    namespace swapping_numbers
    {
        class Program
        {
            static void Main(string[] args)
            {
                int first, second;
                Console.WriteLine("ENTER FIRST NUMBER :- ");
                first = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("ENTER SECOND NUMBER :- ");
                second = Convert.ToInt32(Console.ReadLine());
                first = first + second;
                second = first - second;
                first = first - second;
                Console.WriteLine("VALUES AFTER SWAPPING :- {0} {1} ",first,second);
                Console.ReadLine();
            }
        }
    }	
	

Output

	
   ENTER FIRST NUMBER :- 5
   ENTER SECOND NUMBER :- 2
   
   VALUES AFTER SWAPPING :- 2 5
           

Post Your Comment