VB程序设计:从键盘输入10个互不相同的100以内的整数,放在一维数组中。
从键盘输入10个互不相同的100以内的整数,放在一维数组中。用随机函数产生一个100以内的整数X,如果X比数组中最大的数还大,或者比最小的数还小,或者与数组中的一个数相等...
从键盘输入10个互不相同的100以内的整数,放在一维数组中。用随机函数产生一个100以内的整数X,如果X比数组中最大的数还大,或者比最小的数还小,或者与数组中的一个数相等,则重新生成X。输出X的值。
Private Sub Form_Click()
Randomize
Dim a(1 To 10)
a(1) = InputBox("请输入第1个100以内的整数")
If a(1) > 100 Or a(1) < 0 Then MsgBox "请输入100以内的整数"
For r = 2 To 10
a(r) = InputBox("请输入第" & r & "个100以内的整数")
For i = 1 To r - 1
If a(i) = a(r) Then
MsgBox "输入的数不能有重复"
a(r) = InputBox("请输入第" & r & "个100以内的整数")
Next i
Next r
Min = 100
Max = 0
For r = 1 To 10
If a(r) > Max Then Max = a(r)
If a(r) < Min Then Min = a(r)
Next r
Do
f = 1
X = Int(Rnd(1) * 100)
For r = 1 To 10
If Not (Min < X And Max > X And X <> a(r)) Then f = 0
Exit For
End If
Next r
If f = 1 Then Print X
Exit Do
End If
Loop
End Sub 展开
Private Sub Form_Click()
Randomize
Dim a(1 To 10)
a(1) = InputBox("请输入第1个100以内的整数")
If a(1) > 100 Or a(1) < 0 Then MsgBox "请输入100以内的整数"
For r = 2 To 10
a(r) = InputBox("请输入第" & r & "个100以内的整数")
For i = 1 To r - 1
If a(i) = a(r) Then
MsgBox "输入的数不能有重复"
a(r) = InputBox("请输入第" & r & "个100以内的整数")
Next i
Next r
Min = 100
Max = 0
For r = 1 To 10
If a(r) > Max Then Max = a(r)
If a(r) < Min Then Min = a(r)
Next r
Do
f = 1
X = Int(Rnd(1) * 100)
For r = 1 To 10
If Not (Min < X And Max > X And X <> a(r)) Then f = 0
Exit For
End If
Next r
If f = 1 Then Print X
Exit Do
End If
Loop
End Sub 展开
1个回答
展开全部
'改别人的程序费脑,改你的程序费粮食!
Private Sub Form_Click()
Dim a(10) As Integer
Dim i As Integer
Dim r As Integer
Dim x As Integer
Dim max As Integer
Dim min As Integer
Randomize
Do While i <= 9
a(i) = Val(InputBox("请输入第" & i + 1 & "个100以内的整数"))
If a(i) > 100 Or a(i) < 0 Then
MsgBox "请输入100以内的整数"
Else
For r = 0 To i - 1
If a(i) = a(r) Then
MsgBox "输入的数不能有重复"
Exit For
End If
Next
If r = i Then i = i + 1
End If
Loop
max = 0
min = 100
For r = 0 To 9
If a(r) > max Then max = a(r)
If a(r) < min Then min = a(r)
Next
Do
f = 1
x = Int(Rnd * 100)
For r = 0 To 9
If Not (min < x And max > x And x <> a(r)) Then
f = 0
Exit For
End If
Next
If f = 1 Then
MsgBox x
Exit Do
End If
Loop
End Sub
Private Sub Form_Click()
Dim a(10) As Integer
Dim i As Integer
Dim r As Integer
Dim x As Integer
Dim max As Integer
Dim min As Integer
Randomize
Do While i <= 9
a(i) = Val(InputBox("请输入第" & i + 1 & "个100以内的整数"))
If a(i) > 100 Or a(i) < 0 Then
MsgBox "请输入100以内的整数"
Else
For r = 0 To i - 1
If a(i) = a(r) Then
MsgBox "输入的数不能有重复"
Exit For
End If
Next
If r = i Then i = i + 1
End If
Loop
max = 0
min = 100
For r = 0 To 9
If a(r) > max Then max = a(r)
If a(r) < min Then min = a(r)
Next
Do
f = 1
x = Int(Rnd * 100)
For r = 0 To 9
If Not (min < x And max > x And x <> a(r)) Then
f = 0
Exit For
End If
Next
If f = 1 Then
MsgBox x
Exit Do
End If
Loop
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询