Visual Basic

Moderators: None (Apply to moderate this forum)
Number of posts: 55384

This Forum Only

Prime Number or NOT Posted by lerkana on 3 Oct 2012 at 7:37 AM
'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

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic