Coffee Room

Discuss anything here - everything that you wish to discuss with fellow engineers.

12940 Members

Join this group to post and comment.

# 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.π

if you dont give code then atleast give me algorithem .π

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 Subwhen i insert 100 in text bos the result will be :

1 2 3 5 7can 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 .π

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?

- 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.

- 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.

thanks Maro i was not able to find the result just besouse of simple mistake

"Mod 9 = 0," but now i got result.

"Mod 9 = 0," but now i got result.

How about finding prime number in just one line using Perl π

perl -E 'say "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' 1987

perl -E 'say "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' 1987