www.rtmj.net > vB编程,使用随机函数产生0~10之间的随机整数,形...

vB编程,使用随机函数产生0~10之间的随机整数,形...

Private Sub Command1_Click() Dim i As Integer, j As Integer, a(6, 6) As Integer For i = 1 To 6 For j = 1 To 6 Randomize a(i, j) = Fix(Rnd * 10) Print a(i, j); Next Print Next Print For i = 1 To 6 For j = 1 To 6 Print i & j & " "; Next Print Next End Sub

vb 产生随机数的公式 (上界-下界+1)*rnd+下界 你的题目就应该是 (99-10+1)*rnd +10 一般用rnd的时候还要在前面加一条 randomize 初始化随机种 子 随机数产生的不是正整 数,是带小数的整数.如果你要正整数就用int函数 int((99-10+1)*rnd +10)

private sub command3_click() '用vb编程:随机产生10个0~100之间的随机整数,存放在一个数组中, '然后求个元素和、平均值,统计 '大于平均值的元素个数并把它们显示出来? dim myvalue(100) as integer dim i as integer dim n as integer

private sub command1_click() dim a(10), i, j as integer for i = 0 to 9 a(i) = int(rnd * 100) + 1 print a(i); next for i = 0 to 8 for j = i to 9 if a(i) > a(j) then t = a(i) a(i) = a(j) a(j) = t end if next next print for i = 0 to 9 print a(i) next end sub

Private Sub Form_Load()RandomizeDim intRnd As IntegerDim strRnd As StringDim strOushu As StringDim i As IntegerFor i = 0 To 9intRnd = Int(rnd * 100)strRnd = strRnd & intRnd & ","If intRnd Mod 2 = 0 Then strOushu = strOushu & intRnd & ","NextLabel1.Caption = strRndLabel2.Caption = strOushuEnd Sub

一、要产生1到100之间的随机数,首先了解Rnd函数的用法,Rnd函数产生的是0和1之间的随机数,范围是[0,1),包括0,但不包括1.因此要产生1~100之间的随机数,可以使用Rnd*98,产生的是[0,98)的随机数,而int(Rnd*98)产生的是[0,

Private Sub Form_Click() Me.Cls Dim n(1 To 10) As Integer Dim i%,nMax%,pos% Dim str As String '产生10个0-100的随机数并写入数组 Randomize For i = 1 To 10 n(i) = Int((100 - 0 + 1) * Rnd + 0) str = str & n(i) & " " Next i '找最大值 nMax=

Private Sub Command1_Click() Randomize Dim a(10) As Integer, imas as integer, imin as integer, Average as integer imax = 49 imin = 101 Average=0 For i = 0 To 9 a(i) = Int(Rnd * 51) + 50 Average=Average+a(i) If imax < a(i) Then imax = a(i) If

Sub t() Dim i奇数 As Integer i奇数 = 0 Dim i偶数 As Integer i偶数 = 0 Dim allNumber As String Dim iTemp As Integer For i = 1 To 10 iTemp = Rnd * 90 + 10 If i > 1 Then allNumber = allNumber & "," End If allNumber = allNumber & iTemp If iTemp

Private Sub Command1_Click() Dim a(10) As Integer Randomize Max = 1 For i = 1 To 10 a(i) = 1 + Int(Rnd * 100) Print a(i); If a(i) > a(Max) Then Max = i Next i Print Print "a("; Max; ")="; a(Max)End Sub

网站地图

All rights reserved Powered by www.rtmj.net

copyright ©right 2010-2021。
www.rtmj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com