;

C# program to swap two numbers using a third variable or using a temporary variable


Tutorialsrack 02/05/2019 C# Programs

In this C# program, we will learn how to swap two numbers using a third variable or using a temporary variable.

Here is the Code of Program to swap two numbers using a third variable or using a temporary variable:

Code - swap two numbers using a third variable or using a temporary variable
using System;

namespace SwapNumberUsing3rdVariable
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 5, b = 10, temp;
            Console.WriteLine("Number Before swap a= {0} and b= {1}", a, b);
            //swapping Logic
            temp = a;
            a = b;
            b = temp;
            Console.Write("Number After swapping a= {0} and b= {1}", a, b);
            Console.ReadLine();
        }
    }
}
Output

Number Before swap a= 5 and b= 10

Number After swapping a= 10 and b= 5


Related Posts



Comments

Recent Posts
Tags