mdsk.net
当前位置:首页 >> vB产生10到100的随机数 >>

vB产生10到100的随机数

Dim a(10) As IntegerMin = 100: Max = 1For i = 1 To 10Randomizea(i) = Int(Rnd(1) * 100 + 1)Label1.Caption = Label1.Caption & Str(a(i))Sum = Sum + a(i)If a(i) > Max Then Max = a(i)If a(i) 评论0 0 0

Randomize msgbox Int(Rnd * (100 - 10 + 1)) + 10

可用冒泡排序法:代码如下:'不重复随机数排序'添加 Command1 Command2 Command3Option Explicit Dim i&, j&, k&, t&, Trec&, Arr&(), RndVal&, TmpVal&, S Private Sub Form_Load() Command1.Caption = "选随机数" Command2.Caption

Dim Num1%, Num2%Num1 = 0: Num2 = 0RandomizeFor i = 1 To 12 Num2 = Int(Rnd * 101) + 1 If Num2 >= 50 Then Num1 = Num1 + Num2 If Num1 > 90 Then Exit ForNext iMsgBox Num1以上代码在循环中产生12个1~100的随机数,大于等于50的数将会相加,当相加的值大于90时立即停止计算并使用对话框显示最终值

'方法1,不是你的方法,呵呵,直接产生10个随机数记性排列,谁知道是怎么产生的 ,呵呵.randomizedim a(9)for i=0 to 9a(i)=int(rnd*300+101)next iFor j = 0 To 8 For k = 0 To 8 - j If a(k) > a(k + 1) Then T = A(k) a(k) = a(k + 1) a(k + 1) = T End If

Dim X(10)Option ExplicitPrivate Sub Command1_Click() Dim I As Integer 'Randomize Text1.Text = "" For I = 1 To 10'**********found************* '请不要删除该行' X(I) = Int(Rnd * 100) Text1.Text = Text1.Text & Str(X(I)) & " " '加空格以隔开每个数

'方法1,不是你的方法,呵呵,直接产生10个随机数记性排列,谁知道是怎么产生的 ,呵呵.randomize dim a(9) for i=0 to 9 a(i)=int(rnd*300+101) next i for j = 0 to 8 for k = 0 to 8 - j if a(k) > a(k + 1) then t = a(k) a(k) = a(k + 1) a(k + 1) = t end if next

Private Sub Command1_Click() Dim a(10) As Integer, n As Integer Dim i As Integer, k As Integer Randomize a(1) = Int(Rnd * 90) + 10 k = 1 Do n = Int(Rnd * 90) + 10 For i = 1 To 10 If a(i) = n Then Exit For Next i If i > 10 Then k = k + 1 a(k) = n End If

Private Sub Form_Click() Dim a(9) As Integer, max As Integer, min As Integer, arg As Single, i As Integer Randomize For i = 0 To 9 a(i) = Int(Rnd * 100) + 1 arg = arg + a(i) If i = 0 Or a(i) > max Then max = a(i) If i = 0 Or a(i) < min Then min = a(i) Print

dim a(10) as integer randomize for i=1 to 10 a(i)=int(100*rnd)+1 next i

网站首页 | 网站地图
All rights reserved Powered by www.mdsk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com