22. Write a VB program to check whether the given Armstrong number is present in array or not.


Private Sub cmdClear_Click()
Form1.Cls
End Sub

Private Sub cmdDisplay_Click()
Dim a() As Integer
Dim r, num As Integer
Dim s As Integer
n = InputBox(“How many elements do u want to enter”)
ReDim a(n)
Print “Array is : ”
For i = 0 To n – 1
a(i) = Val(InputBox(“Enter the Elements”))
Print a(i)
Next
For i = 0 To n – 1
s = 0
num = a(i)
While num > 0
r = num Mod 10
s = s + (r * r * r)
num = num \ 10
Wend
If a(i) = s Then
flag = 1
End If
Next
If flag = 1 Then
MsgBox “Armstrong number is present in the array”, vbInformation, “ArmstrongNumber”
Else
MsgBox “Armstrong number is not present in the array”, vbInformation, “ArmstrongNumber”
End If
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s