Pages

Search This Blog

Check whether the given number is Armstrong Number or not



Module ArmstrongNumber

    Sub Main()
        Dim n, r, sum, t As Integer
        Console.Write("Enter a number= ")
        n = CInt(Console.ReadLine())
        sum = 0
        t = n
        While n <> 0
            r = n Mod 10
            sum += Math.Pow(r, 3)
            n = n \ 10

        End While
        If sum = t Then
            Console.WriteLine(t.ToString + " is a Armstrong Number")
        Else
            Console.WriteLine(t.ToString + " is NOT an Armstrong Number")
        End If
        Console.ReadLine()
    End Sub

End Module

23 comments:

  1. Thank You So much. . .

    ReplyDelete
  2. Thank You So much very easy and understanding method :)

    ReplyDelete
  3. this only works for 3 digits number , can you make it work for longer numbers?

    ReplyDelete
  4. Hey Willy just replace 3 with ur no or asign the num

    ReplyDelete
  5. Very informative article.Thank you author for posting this kind of article .


    http://www.wikitechy.com/view-article/c-program-to-check-armstrong-number-with-example-and-explanation



    Both are really good,
    Cheers,
    Venkat

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This code will only work for 3 digit numbers so [sum += Math.Pow(r, 3)] need to be replaced with [sum+=(r*r*r)]

    ReplyDelete
  8. what is the meaning of this "<>" symbol ?




    ReplyDelete
  9. it only works with 3 digit number. How to use it with any number

    ReplyDelete
  10. Mere labtop par banate hai error a arahi hai yahi program Armstrong

    ReplyDelete