Visual Basic

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.