Pages

Search This Blog

Swapping of 2 integers Using Function


Module SwapByFunction

    Sub Main()
        Dim a, b As Integer
        swap(a, b)
        Console.ReadLine()
    End Sub
    Sub swap(ByVal a, ByVal b)
        Dim t As Integer
        Console.Write("a = ")
        a = CInt(Console.ReadLine())
        Console.Write("b = ")
        b = CInt(Console.ReadLine())
        Console.WriteLine()
        Console.WriteLine("Before Swapping...")
        Console.WriteLine("a = " + a.ToString() + " b = " + b.ToString())
        t = a
        a = b
        b = t
        Console.WriteLine()
        Console.WriteLine("After Swapping...")
        Console.WriteLine("a = " + a.ToString() + " b = " + b.ToString())
    End Sub

End Module

2 comments: