Prime Number (Help Plz!)

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 7
Reputation: miss.A is an unknown quantity at this point 
Solved Threads: 0
miss.A miss.A is offline Offline
Newbie Poster

Prime Number (Help Plz!)

 
0
  #1
Mar 11th, 2008
i have to create application that ask user to input Lower bound and upper bound (both intger) greater than 1 and determins all of the prime numbers within the specified bounds, inclusive. and write function procedure prime that returns True if a number is prime. False otherwise. i also should use error provider.


i wrote these 2.. but both are not working ??
i don't know where is my mistake
any help plz ??

i have to submit my project tomorrow

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim i As Integer
Dim a As Integer
Dim b As Integer

ListBox1.Items.Add(Prime(Val(TextBox1.Text))


For i = a To b

ListBox1.Items.Add(i)

Next

End Sub
Function Prime(ByVal b As Integer) As Boolean
Dim i As Integer
Dim a As Integer
a = TextBox1.Text
b = TextBox2.Text

For i = a To b - 1
If b Mod a = 0 Then
Prime = False
Exit Function
End If

Next i
Prime = True
ListBox1.Items.Add(i)
Return a
End Function
End Class
Public Class Form1
Dim i As Integer
Dim n As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Private Sub btnCalP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalP.Click



a = Val(txtLoBo.Text)
b = Val(txtUpBo.Text)
lstPN.Items.Add(Prime(Val(txtLoBo.Text), Val(txtUpBo.Text)))

For i = a To b
If b Mod 2 <> 0 Then
lstPN.Items.Add(c)
End If
Next

End Sub

Function Prime(ByVal a As Integer, ByVal b As Integer) As Integer


Dim flag As Boolean = True

If a Mod 2 <> 0 Then
For c = 2 To b - 1
If a Mod c = 0 Then
flag = False


Else
lstPN.Items.Add(c)
flag = True
End If
Next
end if

Return flag = True
Return flag = False
End Function

End Class
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Prime Number (Help Plz!)

 
0
  #2
Mar 11th, 2008
first you must know the type and patern of prime number :
Hope the following code is solved your problem :
  1. Private Sub PrimeNumber(ByVal Low As Integer, ByVal Up As Integer)
  2. Dim i As Integer
  3. For i = Low To Up
  4. If (i = 2) Or (i = 3) Or (i = 5) Or (i = 7) Then
  5. ListPN.Items.Add(i)
  6. Else
  7. If (i Mod 2 <> 0) And (i Mod 3 <> 0) And (i Mod 5 <> 0) And (i Mod 7 <> 0) Then
  8. ListPN.Items.Add(i)
  9. End If
  10. End If
  11. Next
  12. End Sub
  13.  
  14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15. ListPN.Items.Clear()
  16. PrimeNumber(txtLower.Text, txtUpper.Text)
  17. End Sub

Hope this helps.
don't forget to give feedback
Last edited by Jx_Man; Mar 11th, 2008 at 5:25 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: miss.A is an unknown quantity at this point 
Solved Threads: 0
miss.A miss.A is offline Offline
Newbie Poster

Re: Prime Number (Help Plz!)

 
0
  #3
Mar 11th, 2008
Thaaaaaaaaaaaaaaaaaaaaaaaaaaaanks 4 ur helping..

it's work now
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Prime Number (Help Plz!)

 
0
  #4
Mar 11th, 2008
you're welcome
don't forget to mark this thread solved
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: miss.A is an unknown quantity at this point 
Solved Threads: 0
miss.A miss.A is offline Offline
Newbie Poster

Re: Prime Number (Help Plz!)

 
0
  #5
Mar 12th, 2008
Originally Posted by Jx_Man View Post
you're welcome
don't forget to mark this thread solved
i have problem with the result

if i enter 1 , 199

it give all prime numbers between to thses nums

but it give also 200 which is even num. and it's not between 1 and 199 ??
Last edited by miss.A; Mar 12th, 2008 at 7:06 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Prime Number (Help Plz!)

 
0
  #6
Mar 12th, 2008
i have tried it. and i don't get result 200.just between 1-199.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC