Pages

Search This Blog

Calculate Sum of the digits of a given number


Module sumofdigits

    Sub Main()
        Dim n, sum, r As Integer
        Console.Write("Enter a Number: ")
        n = CInt(Console.ReadLine())
        sum = 0
        While n <> 0
            r = n Mod 10
            sum += r
            n \= 10
        End While
        Console.WriteLine("Sum of Digits=" + sum.ToString())
        Console.ReadLine()
    End Sub

End Module

16 comments:

  1. good ans i got my solution thank you so much
    one of my suggestion is to provide result the entire query
    greeting http://aptiko.com

    ReplyDelete
  2. woowwww its amazing juz because of your answer v r approved as talented thankyou bro

    ReplyDelete
  3. Gives wrong output for 999

    ReplyDelete
  4. not workin for large no.
    working fine for small no.

    ReplyDelete
  5. working fine for 999 too

    ReplyDelete
  6. Nice post,and good information Thanks for sharing further check it once at
    .NET Online Training Hyderabad

    ReplyDelete