2.任意生成10个随机数,找出最大值及最小值所在的位置,并把二者对调,然后输出调整后的确10个整数.
3.产生100个1000以内的随机整数,放入数组a()中,然后查找并输出这100个数中最大值max及最小指min
三到编成题目...请大小高手帮助
3.
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Randomize
For i = 1 To 100
a(i) = Int(Rnd * 1000)
Text1.Text = Text1.Text + Str(a(i))
Next i
For i = 1 To 99
If a(i) > a(i + 1) Then
t = a(i + 1)
a(i + 1) = a(i)
a(i) = t
End If
Next i
Text2.Text = a(i)
For i = 1 To 99
If a(i) < a(i + 1) Then
t = a(i + 1)
a(i + 1) = a(i)
a(i) = t
End If
Next i
Text2.Text = Text2.Text & " " & a(i)
End Sub
1.
Private Sub Command1_Click()
dim s as integer
dim n as integer
s=1
n=1
do
s=s*n
if s>5000 or s=5000 then
print i-1
exit sub
end if
i=i+1
loop
end sub
2.
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 1000)
Text1.Text = Text1.Text + Str(a(i))
Next i
For i = 1 To 9
If a(i) > a(i + 1) Then
t = a(i + 1)
a(i + 1) = a(i)
a(i) = t
End If
Next i
s = a(i)
For i = 1 To 9
If a(i) < a(i + 1) Then
t = a(i + 1)
a(i + 1) = a(i)
a(i) = t
End If
Next i
s1 = a(i)
Text2.Text = Replace(Text1.Text, Str(s), " b") '交换最大值与最小值的位置
Text2.Text = Replace(Text2.Text, Str(s1), Str(s))
Text2.Text = Replace(Text2.Text, " b", Str(s1))
MsgBox "最大值为" & s & "最小值为" & s1
End Sub