Dim a(1000) As Long `esta función determina si el número es primo

Anuncio
ITS “JUAN DE VELASCO”
NOMBRE:ROBERTO ORTIZ
CURSO:SEXTO F
Dim a(1000) As Long
'esta función determina si el número es primo
Private Function esPrimo(i) As Boolean
Dim mValor As Long
Dim mHasta As Long
Dim mRetorno As Boolean
mRetorno = True mValor = 2 mHasta = Int(i / 2)
While (mValor <= mHasta)
And mRetorno
If i Mod mValor = 0
Then mRetorno = False End If mValor = mValor + 1 Wend
esPrimo = mRetorno
End
Function Private Sub Form_Load()
Dim i As Long
Dim q As Long q = 1 i = 1
While q <= 1000
If esPrimo(i)
Then a(q) = i q = q + 1
Debug.Print (i)
End If
i=i+1
Wend
End Sub
Descargar