Write a Vb.net program to accept n numbers through InputBox and count the number of Armstrong and Perfect numbers among them and display their count by using messagebox.
Design:-
Program:-
Public Class slip5
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'global declaration of variables
Dim n As Integer
Dim a(10) As Integer
Dim prime As Integer
Dim remainder, sum, copy As Integer
Dim c, cn As Integer
'Accept n numbers from user
n = InputBox("Enter how many number: ")
For i As Integer = 0 To n - 1
a(i) = InputBox("Enter Element:- ", i)
Next
' Prime logic
prime = 0
For i As Integer = 0 To n - 1
For j As Integer = 2 To a(i) / 2
If a(i) Mod j = 0 Then
prime = 1
Exit For
End If
Next
If prime = 0 Then
c = c + 1
End If
' Armstrong Logic
copy = a(i)
sum = 0
While a(i) > 0
remainder = a(i) Mod 10
sum = (remainder * remainder * remainder) + sum
a(i) = a(i) \ 10
End While
If copy = sum Then
cn = cn + 1
End If
prime = 0
Next
' Print Total of armstrong and perfect number
MsgBox("Total number of perfect Number: " + CStr(c))
MsgBox("Total number of armstrong Number: " + CStr(cn))
End Sub
End Class
Design:-
1) Take Button on the design form.
2) Set Text on Button
Note - Set startup form's application type as Windows Form Application
0 Comments