vb随机生成10个数并显示在一个文本框中, 并找出最大数,指出它的位置
展开全部
添加一个text1,输入以下代码,然后运行。单击窗体,十个随机数显示在text1中,弹出对话框,提示第几个为最大数,并将最大数选中。
Private Sub form_Click()
Dim a(1 To 10) As Integer, i As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1.Text & Space(2) & a(i)
Next
Max = a(1)
For i = 1 To 10
Max = IIf(Max >= a(i), Max, a(i))
Next
For i = 1 To 10
If a(i) = Max Then
MsgBox "最大数为第" & i & "个"
Text1.SetFocus
Text1.SelStart = i * 4 - 2
Text1.SelLength = 2
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub form_Click()
Dim a(1 To 10) As Integer, i As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1.Text & Space(2) & a(i)
Next
Max = a(1)
For i = 1 To 10
Max = IIf(Max >= a(i), Max, a(i))
Next
For i = 1 To 10
If a(i) = Max Then
MsgBox "最大数为第" & i & "个"
Text1.SetFocus
Text1.SelStart = i * 4 - 2
Text1.SelLength = 2
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
展开全部
var str=""
for i as integer =0 to 9
Randomize()
Dim r As int= Cint(Rnd() * 1)
str&=Cstr(r)
next
textbox1.text=str
var sz=str.ToCharArray().Max()
var wz=str.IndexOf(sz)
MsgBox("最大数字" & sz & "在" & wz)
for i as integer =0 to 9
Randomize()
Dim r As int= Cint(Rnd() * 1)
str&=Cstr(r)
next
textbox1.text=str
var sz=str.ToCharArray().Max()
var wz=str.IndexOf(sz)
MsgBox("最大数字" & sz & "在" & wz)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim max1, wz As Integer
For i = 1 To 10
Randomize
Text1 = Text1 & Int(Rnd * 100 + 1) & Space(1)
Next
t = Split(Text1, " ")
max1 = t(0)
wz = 1
For i = 1 To UBound(t) - 1
If Val(t(i)) > max1 Then
max1 = Val(t(i))
wz = i + 1
End If
Next
Print "最大值为" & max1 & "," & "位置为:" & wz
End Sub
Dim max1, wz As Integer
For i = 1 To 10
Randomize
Text1 = Text1 & Int(Rnd * 100 + 1) & Space(1)
Next
t = Split(Text1, " ")
max1 = t(0)
wz = 1
For i = 1 To UBound(t) - 1
If Val(t(i)) > max1 Then
max1 = Val(t(i))
wz = i + 1
End If
Next
Print "最大值为" & max1 & "," & "位置为:" & wz
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个不难啊,不过我不会,不好意思楼主.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询