Q9 write a program to count the digit of the given number.

The code for this program is as follows:

Module Module1

Sub Main()
Dim no, c As Integer
Console.Write("Enter any number : ")
no = Console.ReadLine()
c = 0
While (no > 0)
no = no / 10
c = c + 1
End While
Console.WriteLine("Number of Digits in given number is: {0}", c)

End Sub

End Module

In main() function we have declared a variables no, c. Now we have used the Console.Write function that shows message “Enter any number :”; and when we enter any number then this number is read by Console.ReadLine function and assign to no variable.

Here we have used a while loop. Here we have used the condition no>0 means loop will be continued while the value of no variable is greater than 0. Inside the loop, now we have to get the next digit so that we have used the no/10 and assign it to no. now we have incremented the value of c by one so that while loop will iterate any number of times to reach the no>0 till the c will be incremented by 1 and we get the number of digits of input. The output is as follows: