Q10 write a VB Console application to sum of digit of given integer positive number.
In this application, we will calculate the sum of digit of given number that is a positive integer using the loop. For example if user enters 12345 as number then output will be 15 (1+2+3+4+5).
The Default.aspx file is as follows:
Dim n, sum As Integer
n = System.Console.ReadLine()
sum = 0
While n > 0
sum = sum + n Mod 10
n /= 10
System.Console.Write("Sum of digit is==" & sum)
In this program we have declared n,sum variables. And used Console.Write to display message and Console.ReadLine to get entered input in n variable.Here we have used logic for sum of digit of given number. Here first line is used to get the input from user of string type and get converted into integer type. After that we have declared variable sum=0; after that we have used a while loop and test a condition n>0. this loop will be continued till the condition will not false. The output is as follows: