This website completely moved to new platform. For latest content, visit www.programmingposts.com

Search this Site

18 Aug 2013

VB.Net Program to find the Number Palindrome or not

Module Module1

    Sub Main()
        Dim num As Integer, remainder As Integer, sum As Integer = 0, temp As Integer
        Console.WriteLine("*** www.ProgrammingPosts.blogspot.com ***")
        Console.WriteLine(vbLf & " >>>> To Find a Number is Palindrome or not <<<< ")
        Console.Write(vbLf & " Enter a number: ")
        num = Convert.ToInt32(Console.ReadLine())
        temp = num
        While Convert.ToBoolean(num)
            remainder = num Mod 10
            'for getting remainder by dividing with 10
            num = num \ 10
            'for getting quotient by dividing with 10
            'multiplying the sum with 10 and adding remainder
            sum = sum * 10 + remainder
        End While
        Console.WriteLine(vbLf & " The Reversed Number is: {0} " & vbLf, sum)
        If temp = sum Then
            'checking whether the reversed number is equal to entered number
            Console.WriteLine(vbLf & " The given Number is Palindrome ")
        Else
            Console.WriteLine(vbLf & " The given Number is not a palindrome ")
        End If
        Console.ReadLine()
    End Sub

End Module

Sample Output: