Results 1 to 3 of 3

Thread: how to generate prime numebers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2009

    how to generate prime numebers

    I want to rite an application that will print first n prime numbers. For example if user enters 7 you should display:
    2 3 5 7 11 13 17
    Assume that the user will enter only integer values from 1 to 100.

    this is what I have so far

    Dim intNum As Integer
    Dim intX As Integer
    Dim strOut As String
    Dim intPrime As Integer
    Dim intFactor As Integer

    Private Sub cmdFind_Click()
    intNum = txtNumber.Text
    intPrime = 1
    intFactor = 1

    Do While intPrime <= intNum
    intFactor = intFactor + 1
    intPrime = intPrime + 1

    If intFactor Mod intPrime = 0 Then
    strOut = strOut & intPrime & Space(3)

    End If


    lblPrime.Caption = strOut

    End Sub

  2. #2
    Addicted Member ZenDisaster's Avatar
    Join Date
    Dec 2006
    Bay Area, CA

    Re: how to generate prime numebers

    Check this link.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Chelmsford UK

    Re: how to generate prime numebers

    Quote Originally Posted by ZenDisaster View Post
    Check this link.
    if that doesn't help, search this forum. this question has been asked before

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width