Quick list of numbers

xiaoxiao2021-03-05  23

I haven't come here for a long time. I have recently been seen a number of articles in the number of pictures, benefiting a lot. When you think of VB in our beginners, use the number of cyclic looks to the number of compulsory classes, and write two codes of the number of enumerated numbers and detailed. I feel faster. code show as below:

'********************************************************** ************************************** TARGET: TO GET All Prime Numbers Smaller Than Certain Number

'Author: Northwolves

'Reference: "Sieve of E Eratosthenes"

'CreateDate: 2005-04-18 00:00:00

'********************************************************** *****************************

Sub showprime1 (byval max as long) 'Find All Prime Numbers Smaller Than Max (Max> = 3)

DIM P () As Long, i As Long, J AS Long, Number As Long, SQRTMAX As Long, BEPRIME AS BOOLEAN 'DIFINATIONS

Number = 1redim P (1 to number) p (1) = 2 'The unique even prime number numberbug.print P (1)' show the first prime number

IF Max <3 Then EXIT SUB 'Since We Want Do Something

For i = 3 to max step 2 'skip those even number sqrtmax = int (SQR (i)) 1' get the largest non-self fact for i beprime = true 'init for j = 1 to number' Try All Primer Numbers WE HAVE FOUND P (J) = 0 THEN BEPRIME = FALSE: EXIT for 'NOT A Prime Number IF P (J)> SQRTMAX THEN EXIT for' Unless We'll Waste Our Time Next If BEPRIME = TRUE THEN 'Ten IS a prime number number = number 1' add to it's count redim preserve p (1 to number) 'define again p (number) = i debug.print i' Output the prime number endiff

Nextdebug.print "There" & number & "prime number" & max "show some message

End subprivate subss1_click () 'show all prime number number limited 100000end Sub' ********************************************* ************************************************ 'TARGET: TO GET The First N Prime Numbers from 2, 3, ....

'Author: Northwolves

'Reference: "Sieve of E Eratosthenes"

'CreateDate: 2005-04-18 00:00:00

'********************************************************** **********************

Sub showprime2 (Byval n as long) 'get the first n (n> 1) Prime NumBers

DIM P () As Long, I As Long, J AS Long, Number As Long, SQRTMAX As Long, BEPRIME AS BOOLEAN

Number = 1redim p (1 to number) p (1) = 2 'The Unique Even Prime Numberdebug.print 2' Show The First Prime Number

IF n <2 THEN EXIT SUB 'Since We Want Do Somethingi = 3do while number <= n sqrtmax = int (SQR (i)) 1' get the Largest Non-Self Factor of Max BEPRIME = True 'Init for j = 1 To Number 'Try All Primer Numbers We Have Found Before. If i mod p (j) = 0 THEN BEPRIME = false: exit for' NOT A Prime Number if P (j)> SQRTMAX THEN EXIT for 'Unless We'll Waste Our time Next If beprime = True Then 'then it is a prime number number = number 1' add to it's count ReDim Preserve p (1 to number) 'define again p (number) = i Debug.Print i' output the prime number END IFI = I 2 'Skip Those Even NumberLoP

Debug.print "The" & N & "Prime Number IS" & P (Number); "" "'Show Some Message

End Sub

转载请注明原文地址:https://www.9cbs.com/read-34843.html

New Post(0)