Q6 write a program to print the reverse of given number.

The code for this program is as follows:

Module Module1

Dim n, rev As Integer
Sub Main()
System.Console.Write("Enter the number=")
n = System.Console.ReadLine()
rev = 0
While n > 0
rev = rev * 10 + n Mod 10
n /= 10
End While

System.Console.Write("Reverse number is=" & rev)
System.Console.ReadKey()
End Sub

End Module

In this program we have declared a variables n, rev, r. Now we have used theConsole.Write function that shows message “Enter the number :”; and when we enter any number then this number is read by Console.ReadLine function and assign to n variable.

Here we have used a while loop. Here we have used the condition n>0 means loop will be continued while the value of n variable is greater than 0. Inside the loop, first of all we have to calculate the remainder of the n. Because when we use n mod 10 ; this will give the last digit of the number. here we add the value n mod 10 with rev*10 and assign to rev. now we have to get the next digit so that we have used the no/10 and assign it to no. This loop will be continued till the condition will not become false. The output is as follows: