Armstrong Numbers between 1 to 1000

        Option Explicit 'This will restrict us to declare variable 

        Private Sub cmdDisplay_Click()
              Print "Amstrong Numbers are"
              Call Display
       End Sub
       Public Function Display()
             Dim number As Integer
             Dim i As Integer
             Dim reminder As Integer
             Dim sum As Integer
             For i = 2 To 1000
             number = i
             sum = 0
              While number > 0
                  reminder = number Mod 10
                  sum = sum + (reminder * reminder * reminder)
                  number = number \ 10
           If i = sum Then
                 Print i
           End If
        End Function

No comments:

Post a Comment

Note: only a member of this blog may post a comment.