Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.