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

Search this Site

13 Aug 2014

VB.Net Code to get reverse of a Number

VB.Net Code to get Reverse of a Number

In this post, here is the VB.Net code to get the reverse of a number. You can also use this method while checking whether the number is Palindrome.

If the input number and the reversed input number are same, then the number is said to be a Palindrome.

    
    ''' <summary>
    ''' Method to get reverse of a number
    ''' </summary>
    ''' <param name="Num">Number to be reversed</param>
    ''' <returns>reversed input number</returns>
    Public Function ReverseOfNum(Num As Integer) As Integer

        Dim RevNum As Integer = 0
        Dim Remainder As Integer = 0

        While Num > 0
            'for getting remainder by dividing with 10
            Remainder = Num Mod 10
            'for getting quotient by dividing with 10
            Num = Num \ 10
            'multiplying the sum with 10 and adding remainder
            RevNum = (RevNum * 10) + Remainder
        End While

        Return RevNum
    End Function




Posts you may like :

>>> C#.Net Code to get reverse of a Number

No comments:

Post a Comment

Thanks for your comments.
-Sameer