This C# code swaps 2 Numbers. It obtains two numbers from the user and swaps the numbers using a temporary variable.
You can find more similar examples of programming for this programming language in the site.
Here is source code of the C# code that swaps two numbers.
The program output is also shown below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | static void Main(string[] args) { int temp; int num1 = 55; int num2 = 75; Console.WriteLine("Before Swapping"); Console.WriteLine("First Number : {0}",num1); Console.WriteLine("Second Number : {0}", num2); Console.WriteLine(); temp = num1; num1 = num2; num2 = temp; Console.WriteLine("After Swapping"); Console.WriteLine("First Number : {0}", num1); Console.WriteLine("Second Number : {0}", num2); Console.ReadKey(); } |
Output: