vb循环数组过程实验

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:09:53
循环、数组和过程综合程序设计
利用随机函数产生100个10~99之间的随机整数,找出其中的素数。
将随机产生的100个整数存入数组,按每行10个数输出到窗体或文本框中。
用Sub子过程或Function函数过程判断随机整数是否为素数。
将素数按每行10个数在窗体或文本框中输出。

一般的书都有的,,,
自己去翻番吧

option base 1
private sub cmd1_click()
dim a(100) as integer
for i=1 to 100
randomize
a(i)=int(Rnd*90+10)
print a(i)
if i mod 10 =0 then print
next i
print
static x as integer
x=0
for i=1 to 100
Function ss(a(i))
if ss=0 then x=x+1:print a(i)
if x mod 10 =0 then print
next i
End sub

private Function ss(byval n as integer ) as integer
ss=1
for i=1 to n
for j=2 to n
if i mod j=0 then exit for
next j
if j=n then ss=0
next i
End Function