A simple program of swapping of two number without using 3rd variable in C#.
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(); } } }
ENTER FIRST NUMBER :- 5 ENTER SECOND NUMBER :- 2 VALUES AFTER SWAPPING :- 2 5