Q8 write a program to swap two numbers.

The code for this program is as follows:

Module Module1

Sub Main()
Dim a, b, c As Integer
Console.Write("Enter value of a=")
a = Console.ReadLine()
Console.Write("Enter value of b=")
b = Console.ReadLine()
Console.WriteLine("Before swapping")
Console.WriteLine("a=" & a)
Console.WriteLine("b=" & b)
Console.WriteLine("After swapping")
c = a
a = b
b = c

Console.WriteLine("a=" & a)
Console.WriteLine("b=" & b)

Console.ReadKey()
End Sub

End Module

In this program we have declared a variables a, b, c. Now we have used the Console.Write function that shows message “Enter value of a:”; and when we enter any number then this number is read by Console.ReadLine function and assign to a variable. Now we have used the Console.Write function that shows message “Enter value of b:”; and when we enter any number then this number is read by Console.WriteLine function and assign to b variable. Now we have to assign the value of a to c, b to a and c to b after that we get the swapped number, the output is as follows: