Programe to print prime number in visual basic 6.0

hay friends i have written this programme to print prime noumber but it did not give me desired result so can any one herlp me.😕

Private Sub Form_Load()
 'this programm is program to find prime noumbers till
 '100
 'This programe is programmed and coded by
 'Safwan patel
 'you can share this programm no copyrights
 
MsgBox ("PLease enter any noumber under 100 for finding prime no.")
MsgBox ("this programm will find prime noumbers under 100")
End Sub
Private Sub cmdFind_Click()
 ' this code is 4 event when user will click this button
 Dim inti As Integer, intnum As Integer
  ' data verification related to use
  intnum = Val(txtnum.Text)
   ' converts text into number and take it in use
  List1.AddItem 1
  List1.AddItem 2
  List1.AddItem 3
  List1.AddItem 5
  List1.AddItem 7
   ' we are adding this abouve itemes in list1 as
   'we know already this noumbers are prime
   'and also we dont want to waset pc time
 For inti = 4 To intnum Step 1
 
 
 
    If inti Mod 2 = 0 Then  'we are moving all no. which are divisible by 2
      List2.AddItem inti
    Else
         If inti Mod 3 = 0 Then 'after taking all odd no.
                                'we are moving all no. which are divisible by 3
            List2.AddItem inti
         Else
              If inti Mod 5 = 0 Then
                 'agin we are moving all no. which are divisible by 5
                List2.AddItem inti
              Else
                   If inti Mod 7 = 0 Then
                     ' we are moving all no. which are divisible by 7
 
                      List2.AddItem inti
                   Else
                       If inti Mod 9 Then
                        'agin we are moving all no. which are divisible by 9
                          List2.AddItem inti
                       Else
                            List1.AddItem inti
                       End If
                  End If
              End If
         End If
    End If
Next inti
 
 
 
End Sub
 
when i insert 100 in text bos the result will be :
1
2
3
5
7
can any one help me with this i want a programe to print prime noumber till 100
if you dont give code then atleast give me algorithem .😒

Replies

  • safwan
    safwan
    ahh , why no one is replying i know there are enough progrramers of java and also but many knows java please can anyone help me?
  • MaRo
    MaRo
    - This has nothing to do with Java programming, VB is the hell programming language

    - Write Mod 9 = 0, not just Mod 9, the problem is that it checks if inti Mod 9 would results any errors (dividing by zero), it doesn't, So, the program flow won't reach the last else that prints in list1.

    - Add

    List1.Clear
    List2.Clear

    Under 'Private Sub cmdFind_Click()' for better program view.
  • safwan
    safwan
    thanks Maro i was not able to find the result just besouse of simple mistake
    "Mod 9 = 0," but now i got result.
  • Sanjeev Jaiswal
    Sanjeev Jaiswal
    How about finding prime number in just one line using Perl 😉
    perl -E 'say "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' 1987

You are reading an archived discussion.

Related Posts

So I went autocrossing this weekend, first one of the season in the DC area. Got 11 runs in and was able to shave quite a bit of time off...
When we mesh in ansys sometimes it shows mesh in purpole color and sometimes it shows mesh in green color is there any difference in these cases!!!
what are the basic differences between an all terrain car and an ordinary car in terms of steering braking system suspension if possible please forward me a link or an...
Hello guys, So again I am stuck with my filament winding machine. Since the budget for the project is so small, I have to come by using components which the...
i am working with 8051 microcontroller.........the relay is connected with 5vdc motor and i am connecting relay at the port p0.0.i am using the following code to rotate the motor..........