Prime Number or NOT - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Prime Number or NOT

lerkanalerkana Posts: 1Member
'This Program is used to determine whether a value is a prime number or not. Create two text boxes(txtNum and txtTrue) and One Button(Call what you want)

Private Sub cmdPrime_Click(sender As Object, e As EventArgs) Handles cmdPrime.Click
Dim x, y, m As Double
'x will be the number you input in the text box(txtNum.text)
Dim count, v As Double
'count will determine all the numbers that will be used to divide with
x = txtNum.Text
'what ever you input in the textbox(txtNum.text) will be stored in x
y = x - 1
'we only want to divide by numbers less then the given number
m = 0
'm will count the number of times everytime we learn that x is divisable by any number
If x <> 1 Then
'One is not a Prime number at all
For count = 2 To y
v = x Mod count
'when a number is divisable by another, mod will always be zero
If v = 0 Then
m = m + 1
End If
Next
If m > 0 Then
txtTrue.Text = x & " " & "is NOT A PRIME NUMBER"
Else
txtTrue.Text = x & " " & "is A PRIME NUMBER"
End If
Else
txtTrue.Text = x & " " & "is NOT A PRIME NUMBER"
End If

End Sub
Sign In or Register to comment.