Prime Number Function

Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 8
Reputation: geo039 is an unknown quantity at this point 
Solved Threads: 0
geo039 geo039 is offline Offline
Newbie Poster

Prime Number Function

 
0
  #1
Nov 2nd, 2006
I'm trying to write a function that checks for prime numbers and returns true if a number is prime. Something simple, i'm just a beginner. Here's what I have, does it make sense..if not any input would be appreciated.

Function IsPrime(ByVal dblCheck AsDouble) AsBoolean
Dim intNumber As Integer
For intNumber = 2 To dblCheck - 1
If dblCheck Mod intNumber = 0 Then
IsPrime = False
Exit Function
End If
Next intNumber
IsPrime = True
'return prime numbers
Return dblCheck
End Function 'IsPrime
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Prime Number Function

 
0
  #2
Nov 2nd, 2006
Originally Posted by geo039 View Post
I'm trying to write a function that checks for prime numbers and returns true if a number is prime. Something simple, i'm just a beginner. Here's what I have, does it make sense..if not any input would be appreciated.

Function IsPrime(ByVal dblCheck AsDouble) AsBoolean
Dim intNumber As Integer
For intNumber = 2 To dblCheck - 1
If dblCheck Mod intNumber = 0 Then
IsPrime = False
Exit Function
End If
Next intNumber
IsPrime = True
'return prime numbers
Return dblCheck
End Function 'IsPrime
Try google prime number algorithms
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 7401 | Replies: 1
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC