用vb编写*利用随机函数产生20个10~99之间(包括10和99)的随机整数存入一维数组A,
6个回答
展开全部
'只须在窗体内忝加一个command即可
Private Sub Command1_Click()
Cls
Dim a(1 To 20), b(1 To 19)
Randomize
Print "随机生成的这组数是:"
For i = 1 To 20
a(i) = Int(Rnd * 90) + 10
Print a(i);
If i = 10 Then Print
Next
Print
Print
Print "这组数按从大到小的顺序排列每10人一行输出如下:"
For i = 1 To 20
For j = i + 1 To 20
If a(i) < a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next
Print a(i);
If i Mod 10 = 0 Then Print
Next
For i = 1 To 19
b(i) = a(i) - a(i + 1)
Next
x = b(1)
For i = 1 To 19
If x < b(i) Then x = b(i)
Next
Print
Print "相邻两个数的最大差值是:" & x
End Sub
Private Sub Command1_Click()
Cls
Dim a(1 To 20), b(1 To 19)
Randomize
Print "随机生成的这组数是:"
For i = 1 To 20
a(i) = Int(Rnd * 90) + 10
Print a(i);
If i = 10 Then Print
Next
Print "这组数按从大到小的顺序排列每10人一行输出如下:"
For i = 1 To 20
For j = i + 1 To 20
If a(i) < a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next
Print a(i);
If i Mod 10 = 0 Then Print
Next
For i = 1 To 19
b(i) = a(i) - a(i + 1)
Next
x = b(1)
For i = 1 To 19
If x < b(i) Then x = b(i)
Next
Print "相邻两个数的最大差值是:" & x
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Option Base 1
Dim a%(80), i%, k%, t%, b%(80)
Private Sub Command1_Click()
Me.Cls
Dim j As Integer
Randomize
For i = 1 To 80
a(i) = Int(Rnd * 90) + 10
Next i
k = 0
t = 1
For i = 1 To 79
b(i) = Abs(a(i + 1) - a(i))
If b(i) > k Then
k = b(i)
t = i
End If
Next i
Print "全部"
For i = 1 To 80
Print a(i);
If i Mod 10 = 0 Then Print
Next i
Print "最大差值:" & k & ",是" & a(t + 1) & "和" & a(t) & "之差"
End Sub
Option Base 1
Dim a%(80), i%, k%, t%, b%(80)
Private Sub Command1_Click()
Me.Cls
Dim j As Integer
Randomize
For i = 1 To 80
a(i) = Int(Rnd * 90) + 10
Next i
k = 0
t = 1
For i = 1 To 79
b(i) = Abs(a(i + 1) - a(i))
If b(i) > k Then
k = b(i)
t = i
End If
Next i
Print "全部"
For i = 1 To 80
Print a(i);
If i Mod 10 = 0 Then Print
Next i
Print "最大差值:" & k & ",是" & a(t + 1) & "和" & a(t) & "之差"
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim n ,m,a(19),max
max=0
for n=0 to 19
a(n)=int((rnd*90)+10) '生成20个10-99的随机数
next n
for n=0 to 18
for m=n+1 to 19
if a(n)>a(m) then
swap a(n),a(m) ‘排序从小到大
end if
next m
next n
for n=1 to 19
if a(n)-a(n-1)>max then
max=a(n)-a(n-1) ’计算相差最大值,赋值给max
end if
next n
max=0
for n=0 to 19
a(n)=int((rnd*90)+10) '生成20个10-99的随机数
next n
for n=0 to 18
for m=n+1 to 19
if a(n)>a(m) then
swap a(n),a(m) ‘排序从小到大
end if
next m
next n
for n=1 to 19
if a(n)-a(n-1)>max then
max=a(n)-a(n-1) ’计算相差最大值,赋值给max
end if
next n
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim i%, j%, a%(20), max%
max = 0
Randomize
For i = 1 To 20
a(i) = Int((Rnd * 90) + 10) '生成20个10-99的随机数
Print a(i);
Next i
For i = 1 To 19
For j = i + 1 To 20
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t '排序从小到大
End If
Next j
Next i
Print
For i = 1 To 20
Print a(i);
Next i
For i = 2 To 20
If a(i) - a(i - 1) > max Then
max = a(i) - a(i - 1) '计算相差最大值,赋值给max
End If
Next i
Print
Print "max="; max
max = 0
Randomize
For i = 1 To 20
a(i) = Int((Rnd * 90) + 10) '生成20个10-99的随机数
Print a(i);
Next i
For i = 1 To 19
For j = i + 1 To 20
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t '排序从小到大
End If
Next j
Next i
For i = 1 To 20
Print a(i);
Next i
For i = 2 To 20
If a(i) - a(i - 1) > max Then
max = a(i) - a(i - 1) '计算相差最大值,赋值给max
End If
Next i
Print "max="; max
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询