Home >>VB.Net Built-in Functions >VB.Net program to check the given number is palindrome or not using While loop

VB.Net program to check the given number is palindrome or not using While loop

Write a VB.Net program to check the given number is palindrome or not using the While loop

Here, we read the user's integer number and then check if the given number is palindrome or not and print the required message on the screen of the console.

Program :

Palindrome is the source code to check the specified number or not using the While loop below. The program given is compiled and successfully executed.

'VB.Net program to check the given number is

'palindrome or not using the "While" loop.


Module Module1
    Sub Main()
        Dim number As Integer = 0
        Dim remainder As Integer = 0
        Dim reverse As Integer = 0
        Dim temp As Integer = 0
        Console.Write("Enter the number: ")
        number = Integer.Parse(Console.ReadLine())
        temp = number
        While (number > 0)
            remainder = number Mod 10
            reverse = reverse * 10 + remainder
            number = number / 10
        End While
        If temp = reverse Then
            Console.WriteLine("Number is palindrome")
        Else
            Console.WriteLine("Number is not palindrome")
        End If
    End Sub   
End Module
	
Output:
Enter the number: 1234321
Number is palindrome

Explanation:

We created a Module1 module in the above program that contains the function Main (). We have created four integer variables in the main(), number, remainder, reverse, and temp, initialized with 0.

Console.Write("Enter the number: ")
number = Integer.Parse(Console.ReadLine())

temp = number

While (number > 0)
    remainder = number Mod 10
    reverse = reverse * 10 + remainder
    number = number / 10
End While

If temp = reverse Then
    Console.WriteLine("Number is palindrome")
Else
    Console.WriteLine("Number is not palindrome")
End If

We read the user's integer number here and then find the reverse number by finding the remainder of the number before it becomes zero and then comparing the reverse number with the original number, if both are equal then print "Number is a palindrome" otherwise the message "Number is not a palindrome" would be printed on the screen of the console.


No Sidebar ads