mdsk.net
当前位置:首页 >> vB产生10个随机数并显示 >>

vB产生10个随机数并显示

在窗体上放一个label,Caption设为空,然后复制下面的代码就OK了.Private Sub Form_Load() Dim a(9) Randomize (Timer) For i = 0 To 9 a(i) = Rnd * 10000 Label1.Caption = Label1.Caption & a(i) & Chr(13) & Chr(10) Next End Sub

Private Sub Command1_Click()Dim A(9) As DoubleDim B As IntegerDim C As LongDim D As IntegerPrint "10个随机数为:"For B = 0 To 9RandomizeA(B) = Int(Rnd * 9999)Print A(B);If A(B) > C Then C = A(B): D = BNextA(D) = 0C = 0For B = 0 To 9If A(B) > C Then C = A(B)NextPrint Chr(13) & "第二大的那个数为:" & CEnd Sub

Private Sub Command1_Click() Dim i As Integer For i = 1 To 10 Print Int(Rnd() * 90) + 10; Next i Print End Sub Private Sub Form_Load() Command1.Caption = "产生随机数" End Sub

Private Sub Form_Click() Dim a(1 To 10) As Integer dim i as integer, s as string , t as integer s="" For i = 1 To 10 a(i) = Int(Rnd * 69) - 9 s=s & trim(str(a(i))) & " " Next i For i = 1 To 9 For j = i + 1 To 10 If a(i) < a(j) Then t = a(j):a(j) = a(i):a(i) = t

用数组来保存产生的随机数,每产生一个随机数就跟已经产生的随机数进行比较,如果跟已经产生的随机数中的一个相同的话就重新产生一个随机数,直到跟已经产生的所有随机数都不相同为止.Private Sub Command1_Click() Dim a(1 To 10)

按钮的click事件中写上 dim i as integer randomize for i =1 to 10 print int(rnd*90 +10) next 就可以了.

代码如下:private sub form_click()dim temp as integer '申明变量cls '清理窗体dim a(1 to 10) '申明数组变量print "颠倒前:"for i = 1 to 10randomizea(i) = int(rnd * 61 + 20)print a(i);next iprintprint "颠倒后:"for i = 1 to 5temp = a(i)a(i) = a(11 - i)a(11 - i) = tempnext ifor i = 1 to 10print a(i);next iend sub

参考代码:Dim a(9) As Integer Randomize For i = 0 To 9 a(i) = CInt(Rnd() * 10) Next i End Sub

简单啊.建立个窗体,在上面放一个按钮,然后把下面这段代码写到按钮的click事件中,运行程序,点一下按钮就会出来一行随机数.Private Sub Command1_Click()For i = 1 To 10 x = Int(Rnd() * 10) Print x;Next iPrintEnd Sub

Private Sub Form_click() Dim a(9) Dim m(), n() 'm()为偶数集, n()为奇数集 Dim i, p, q Dim sum Dim avg1, avg2 'avg1为奇数平均数, avg2为偶数平均数 Dim max, min For i = 0 To 9 Randomize a(i) = Int(Rnd() * 99 + 1) If a(i) Mod 2 = 0 Then

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