Pages

Search This Blog

Swapping of 2 Variables without using 3rd Variable


Module Swapping
    Sub main()
        Dim a, b As Integer
        Console.Write("Enter the values of a and b:")
        a = CInt(Console.ReadLine())
        b = CInt(Console.ReadLine())
        Console.WriteLine("Before swapping values of a=" + a.ToString() + " b=" + b.ToString())
        a = a + b
        b = a - b
        a = a - b
        Console.WriteLine("After swapping values of a=" + a.ToString() + " b=" + b.ToString())
        Console.ReadLine()
    End Sub
End Module

5 comments: