×

VB.Net Programs

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

By Nidhi Last Updated : October 13, 2024

Checking palindrome number using the While loop in VB.Net

Here, we will read an integer number from the user and then check the given number is palindrome or not and print the appropriate message on the console screen.

Program/Source Code:

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

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

'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
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a function Main(). In the Main(), we created four integer variables number, remainder, reverse, and temp, which are 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

Here, we read the integer number from the user and then find the reverse the number by finding the remainder of the number till it becomes zero and then check the reverse number with the original number, if both are equal then print "Number is a palindrome" otherwise "Number is not a palindrome" message will be printed on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.