TEAM CODING-BCA

VB program to implement Prime No. checking.

PRIME NUMBER


Private Sub Command1_Click()
Dim n1 As Integer
Dim n2 As String
n1 = Val(Text1.Text)
n2 = prime(n1)
MsgBox "no is" & " " & n2
End Sub

Public Function prime(n1 As Integer)
Dim i As Integer
Dim c As Integer
For i = 1 To n1
If n1 Mod i = 0 Then
c = c + 1
End If
Next
If (c = 2 Or n1 = 1) Then
prime = "prime"
Else
prime = "not prime"
End If

End Function



No comments:

Post a Comment