1.11 – Swap two numbers

Question


Write a program to accept two numbers  and display swapping of that numbers.

Solution


class Swapping
    {
        static void Main(string[] args)
        {
            int num1, num2, temp;
            Console.Write(“Enter the First Number : “);
            num1 = Convert.ToInt16(Console.ReadLine());
            Console.Write(“Enter the Second Number : “);
            num2 = Convert.ToInt16(Console.ReadLine());
            temp = num1;
            num1 = num2;
            num2 = temp;
            Console.WriteLine(“\nAfter Swapping”);
            Console.WriteLine(“First Number : “ +num1);
            Console.WriteLine(“Second Number : “ +num2);
        }
    }

 Previous                                              Home                                                     Next


Output


Swap