Wednesday, 20 April 2016

Armstrong number in vb.net


        Dim x As String
        Dim y As Integer
        For index As Integer = 0 To 10000
            x = ""
            y = 0
            Dim x1 As Integer = index
            Dim s As String = x1.ToString
            Dim a(s.Length) As String
            For i As Integer = s.Length - 1 To 0 Step -1
                x = s.Substring(i, 1) & x
                y = y + (s.Substring(i, 1) * s.Substring(i, 1) * s.Substring(i, 1))
            Next
            If Val(x) = y Then
                Label1.Text = Label1.Text & vbCrLf & x
            End If
            Application.DoEvents()
        Next