vb 关于 For…Next循环和Do…Loop循环的问题~~请高手指教!!

来源:百度知道 编辑:UC知道 时间:2024/06/18 14:37:20
27 For…Next循环
熟悉For…Next循环语句。输入N,产生N个1-100的随机数,并计算这N个数的最大数,最小数以及总和。如图7-1所示
28 Do…Loop循环
熟悉Do…Loop循环语句。产生N个1-100的随机数,直到产生的随机数为100时结束,并统计次数。

for i=1 to n
print int(rnd*100+1)
next i

i=0
do
a%=int(rnd*100+1)
i=i+1
print a%
loop until a%=100
print i;"次"

dim rr(99) as integer
dim i,aa,e,f,s
e=0
f=0
s=0
aa=val(inputbox("请输入:"))
for i=0 to aa-1
rr(i)=int(rnd*100+1)
if rr(i)>e then e=rr(i)
if rr(i)<f then f=rr(i)
s=s + rr(i)
next
msgbox("最大值" & e & " 最小值" & f & " 总和" & s)

2、
dim a ,n
do while 1
n=n+1
a=int(rnd*100+1)
if a=100 then
msgbox("共运行了" & n & "次")
exit do
end if
loop