用vb编程:利用随机函数产生50-100范围内的20个随机数,显示其中的最大值、最小值和平均值。
Private Sub Form_Click()
Dim i, num(1 To 20) As Integer, smax As Integer, smin As Integer, savg As Single
savg = 0
Print "50-100范围内的20个随机数如下:"
For i = 1 To 20
num(i) = 50 + Int(51 * Rnd) '产生[50,100]区间的20个随机数
If i = 1 Then smax = num(i): smin = num(i)
If smax < num(i) Then smax = num(i) '求最大值
If smin > num(i) Then smin = num(i) '求最小值
savg = savg + num(i) '求平均值,最后结果要除以数目
Print num(i);
If i Mod 10 = 0 Then Print
Next i
savg = savg / 20
Print
Print "最大值"; smax, "最小值"; smin, "平均值"; savg
End Sub
Private Sub Form_Activate()
Dim a(1 To 20) As Integer, b As Integer, c As Integer, d As Integer, e As Integer
Randomize
Print "随机数:";
For i = 1 To 20
a(i) = Int(Rnd * 50) + 50
If a(i) > d Then d = a(i)
e = e + a(i)
Print a(i);
Next
c = a(1)
For i = 2 To 20
If c > a(i) Then c = a(i)
Next
Print
Print "最小值为:"; c
Print "最大数为:"; d
Print "平均值为:"; e / i
End Sub
Private Sub Command1_Click()
Cls
Scale (0, 0)-(100, 100)
For u = 1 To 20
a(u) = Int(Rnd * 50) + 50
b = b + a(u)
Print a(u)
Next u
c = b / 20
For i = 1 To 19
For j = i + 1 To 20
If a(i) > a(j) Then temp = a(i): a(i) = a(j): a(j) = temp
Next j
Next i
CurrentX = 10: CurrentY = 20
Print "最大值为" & a(20) & " " & "最小值为" & a(1) & " " & "平均值为" & c
End Sub
我试过的 没问题 你看看,有疑问再联系我!!
Private Sub Command1_Click()
Dim 数%, 最大值%, 最小值%, 平均值%, 和%
最小值 = 9999
For i = 1 To 20
数 = Rnd * 50 + 0.5 + 50
Print 数;
If 数 > 最大值 Then 最大值 = 数
If 数 < 最小值 Then 最小值 = 数
和 = 和 + 数
Next i
平均值 = 和 / 20
Print "最小值:" & 最小值
Print "最大值:" & 最大值
Print "平均值:" & 平均值
End Sub
vb编程题~~随机产生20个不重复的A~Z之间的英文字母,按字母顺序输出,每...
给你个思路。首先,定义20个数组。然后在过程里弄个for循环,比如for i = 1 to 20 利用随机函数,生成65~90之间的函数,赋值到变量,比如 str=Int((90 - 65 + 1) * Rnd + 65)再弄个for循环,比如for j = 1 to i 判断是否重复 if 数组名(j)=str then call 过程 exit sub end if n...
在VB中,利用随机函数产生 10个 1---100 之间的随机整数,找出其中能被...
1)Next IFor I = 1 To 19 For J = 1 To 20 - I If AA(J) > AA(J + 1) Then SDA = AA(J) AA(J) = AA(J + 1) AA(J + 1) = SDA End If Next JNext IText1.Text = Text1.Text & "生成的20个随机数:" & vbCrLfFor I = 1 To 20If AA...
用vb做 利用随机函数产生20 个50~100范围内的随机整数,显示它们的最...
Private Sub Form_Click()Dim i, num(1 To 20) As Integer, smax As Integer, smin As Integer, savg As Single savg = 0 Print "50-100范围内的20个随机数如下:"For i = 1 To 20 num(i) = 50 + Int(51 * Rnd) '产生[50,100]区间的20个随机数 If i = 1 Then smax = ...
VB问题:单击窗体,利用随机函数产生20个2位整数,在窗体输出,并判断其...
试编写代码如下:Dim aOdd() As Integer, aEven() As Integer, aAll(1 To 20) As IntegerSub GenArray() Randomize For i = 1 To 20 aAll(i) = Int((90 * Rnd) + 10) NextEnd SubFunction DoSort(arr) For i = LBound(arr) To UBound(arr) - 1 For j =...
vb编程,用随机函数产生50个10~100之间的互不相同的整数存于一数组中...
Private Sub Command1_Click()Dim x(90) As Integer '高效代码,产生无重复随机数 For i = 10 To 100 x(i - 10) = i Next Randomize For i = 1 To 50 j = Int(Rnd * (91 - i)) + i t = x(i)x(i) = x(j)x(j) = t Next '排序 For i = 1 To 50 For j = 1 ...
急求VB编程“利用随机函数产生10个50-100之间的随机整数,求它们的最大...
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 imin > a(i)...
用vb编程:利用随机函数产生50-100范围内的20个随机数,显示其中的最大值...
Dim a(1 To 20) As Integer Private Sub Command1_Click()Cls Scale (0, 0)-(100, 100)For u = 1 To 20 a(u) = Int(Rnd * 50) + 50 b = b + a(u)Print a(u)Next u c = b \/ 20 For i = 1 To 19 For j = i + 1 To 20 If a(i) > a(j) Then temp = ...
在vb中,如何编写程序通过随机函数产生10~99之间的随机整数?
vb 产生随机数的公式(上界-下界+1)*rnd+下界你的题目就应该是(99-10+1)*rnd +10一般用rnd的时候还要在前面加一条 randomize 初始化随机种 子
vb编程题,用随机函数产生10个50以内包括50的随机整数存入一堆数组?_百 ...
Private Sub Command1_Click()Dim a(10) As Integer Randomize Print "产生的随机数是:"For i = 1 To 10 a(i) = Int(Rnd * 51)Print a(i);Next i Print x = CInt(InputBox("请输入要查找的数:"))Print "要查找的数是:"; x n = 0 For i = 1 To 10 If x = a(i) ...
vb编程实现:随机产生一个3位正整数,逆序输出。
Private Sub Form_Load()Dim i As Integer Dim temp As Integer Dim result As String Randomize For i = 1 To 3 temp = Rnd * 10 If temp = 10 Then temp = 1 result = result & Trim(Str(temp))Next Print "随机数:" & result Print "反转后:" & StrReverse(result)End Sub ...
老凤复方: Dim a(1 To 20) As Integer Private Sub Command1_Click() Cls Scale (0, 0)-(100, 100) For u = 1 To 20a(u) = Int(Rnd * 50) + 50b = b + a(u)Print a(u)Next uc = b / 20For i = 1 To 19For j = i + 1 To 20If a(i) > a(j) Then temp = a(i): a(i) = a(j): a(j) =...
红花岗区19821247611: VB利用随机函数生成50 - 100范围内20个随机数,显示最大值,最小值,平均值?
老凤复方: Option Base 1 Private Sub Command1_Click() Dim arr(20) As Integer, max As Integer, min As Integer Dim s As Single Cls max = 50 min = 100 Print "产生的随机数为:" For i = LBound(arr) To UBound(arr) Randomize arr(i) = Int(Rnd * 51) + 50 ...
红花岗区19821247611: VB方面的:利用随机函数产生20个50 -- 100范围内的随机数,显示它们的最大值,最小值,和平均值 - ?
老凤复方: Private Sub Form_click() Dim n(1 To 20) As Integer Dim i, j, ave, temp Randomize For i = 1 To 20 n(i) = Int((51 * Rnd) + 50) Print n(i) Next i For j = 1 To 19 For i = j + 1 To 20 If n(i) >= n(j) Then temp = n(i) n(i) = n(j) n(j) = temp End If Next Next ave = ...
红花岗区19821247611: vb编程,用随机函数产生50个10~100之间的互不相同的整数存于一数组中,并以升序每行10个数显示在窗体上 - ?
老凤复方: Private Sub Command1_Click() Dim x(90) As Integer'高效代码,产生无重复随机数 For i = 10 To 100 x(i - 10) = i Next Randomize For i = 1 To 50 j = Int(Rnd * (91 - i)) + i t = x(i) x(i) = x(j) x(j) = t Next'排序 For i = 1 To 50 For j = 1 To i If x(i) < x(j) Then t ...
红花岗区19821247611: vb生成正负50之间的随机数 - ?
老凤复方: 给你一个公式 int((上限-下限+1)*Rnd+下限) 就可以了
红花岗区19821247611: vb利用随机函数产生50到100范围的30个随机数,显示其中最大值,最小值,平均值,求解 - ?
老凤复方: Private Sub Command1_Click() Dim i, max, min, s As Integer max = 0 min = 100 s = 0 Dim a(30) As Integer Text1.Text = "" Text2.Text = "" Text3.Text = "" Randomize Now For i = 1 To 30 a(i) = Int((100 - 50 + 1) * Rnd + 50) If maxIf min > a(i)...
红花岗区19821247611: VB 编程序用随机函数产生50个100以内的整数放在一维数组中,求出大于90的数及其位置? - ?
老凤复方: 属dim ar(1 to 50) as integer'-------------------------------------------- private sub command1_click() randomize dim i as integer for i=1 to 50 ar(i)=int(100*rnd) next'------------------------------------- for i =1 to 50 if ar(i) >90 then print ar(i) , i end if next end sub
红花岗区19821247611: vb中如何编程产生一个20到50的随机数 - ?
老凤复方: 以下代码产生[20,50]的随机数:20+int(rnd*31)
红花岗区19821247611: VB用随机函数产生50个【10 - 100】的随机整数,并按照从小到大的顺序打印出来 - ?
老凤复方: Dim A(50) As Integer Private Sub Command1_Click() Randomize For i = 1 To 50 A(i) = Int(Rnd * 90 + 10) Next i Picture1.Cls Picture1.Print "排序前数据:" For i = 1 To 50 Picture1.Print A(i); If i Mod 10 = 0 Then Picture1.Print Next End Sub ...
红花岗区19821247611: VB编程:使用随机函数产生50个10~100之间的互不相同的整数,存于一数组中,并以升序每行10个数在图片框上输出??
老凤复方: Command1产生50个随机数并在Picture1输出,Command2排序并在Picture2输出. Private a(50) As Integer Private Sub Command1_Click() Dim i, j, n As Integer Picture1.Cls Randomize Timer For i = 1 To 50 Do Until j > i n = Rnd() * 100 Mod 90 ...