PROPERTIES:
CODEING:
Button1 | |
Text | Prime |
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If IsNumeric(TextBox1.Text) Then
Dim ans As Integer = prime(Val(TextBox1.Text))
If ans = 0 Then
MsgBox(Val(TextBox1.Text) & " is Prime Number")
Else
MsgBox(Val(TextBox1.Text) & " is Not Prime Number")
End If
Else
MsgBox("Enter Numeric Value")
End If
End Sub
Function prime(ByVal num As Integer) As Integer
Dim i As Integer = 2
Dim k As Integer = 0
While i <= num / 2 And k = 0
If num Mod i = 0 Then
k = 1
Else
i += 1
End If
End While
Return k
End Function
End Class
DESIGNING:Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If IsNumeric(TextBox1.Text) Then
Dim ans As Integer = prime(Val(TextBox1.Text))
If ans = 0 Then
MsgBox(Val(TextBox1.Text) & " is Prime Number")
Else
MsgBox(Val(TextBox1.Text) & " is Not Prime Number")
End If
Else
MsgBox("Enter Numeric Value")
End If
End Sub
Function prime(ByVal num As Integer) As Integer
Dim i As Integer = 2
Dim k As Integer = 0
While i <= num / 2 And k = 0
If num Mod i = 0 Then
k = 1
Else
i += 1
End If
End While
Return k
End Function
End Class
Comments
Post a Comment