write program to generate 1 to 20 natural numbers in visual basic
Answers
Explanation:
The sum of a digit is the addition of all the numbers in a number. For example, I want to find the sum of digits of the number 123 so the answer will be 1+2+3 = 6. Let’s see the visual basic program to find the sum of a digit. If you are beginners will be recommended to check more visual basic programs on numbers or mathematical problem.
Algorithm to find the Sum of digit in Visual basic
Enter the number (n=123)
Execute While loop till (n>0)
Separate each digit and perform addition operation with every iteration
Print the sum on console
Visual basic (vb) program to find the sum of a digit
Module Module1
Sub Main()
Dim a, n, sum As Integer
a = 123
sum = 0
While a > 0
n = a Mod 10
sum = sum + n
a = a / 10