ADVERTISEMENT
ADVERTISEMENT

VB.Net program to reverse the given number using the While loop

Here, we are going to learn how to reverse the given number using the While loop in VB.Net?
Submitted by Nidhi, on December 06, 2020

Here, we will read an integer number from the user and then reverse the given number and print on the console screen.

Program/Source Code:

The source code to reverse the given number using the While loop is given below. The given program is compiled and executed successfully.

'VB.Net program to reverse the given number 
'using the "While" loop.

Module Module1

    Sub Main()
        Dim number As Integer = 0
        Dim remainder As Integer = 0
        Dim reverse As Integer = 0

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

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

        Console.WriteLine("Reverse: {0}", reverse)
    End Sub
    
End Module

Output:

Enter the number: 1234
Reverse: 4321
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 three integer variables number, remainder, and reverse, which are initialized with 0.

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

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

Here, we read the integer number from the user and then reverse the number by finding the remainder of the number till it becomes zero and then printed the reverse of the number on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.