vb.net

How to find the largest digit of a number in VB.Net

In this program, You will learn How to find the largest digit of a number in VB.Net.

Write this code for How to find the largest digit of a number in VB.Net?

Imports System

Module Program
    Sub Main(args As String())
        Dim n, r As Integer, digit As Integer = 0
        Console.Write("Enter a number:")
        n = Convert.ToInt32(Console.ReadLine())

        While n  > 0
            r = n Mod 10

            If digit < r Then
                digit = r
            End If

            n = n / 10
        End While

        Console.WriteLine("Largest digit:" & digit)
        Console.ReadLine()

    End Sub
End Module

Advertisement

Output :find the largest digit of a number in VB.Net

Advertisement

Leave a Reply

Your email address will not be published. Required fields are marked *