早教吧作业答案频道 -->其他-->
用函数产生10个随机数并保存a数组中单击查找任意输入一个数在数组a中查找该数OptionBase1Dima(10)PrivateSubCommand1Click()Text1.Text="":Text2.Text=""Fori=1To10a(i)=Fix(Rnd*99+1)Forj=1Toi-1If
题目详情
用函数产生10个随机数 并保存a数组中 单击查找 任意输入一个数 在数组a中查找该数
Option Base 1
Dim a(10)
Private Sub Command1_Click()
Text1.Text = "":Text2.Text = ""
For i = 1 To 10
a(i) = Fix(Rnd * 99 + 1)
For j = 1 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next j
Next i
For i = 1 To 10
Text1.Text = Text1.Text + Str(a(i)) + Space(2)
Next i
End Sub
Private Sub Command2_Click()
Dim num As Integer,i As Integer
num = InputBox("请输入查找的数")
For i = 1 To 10
If a(i) = num Then
Text2.Text = Str(num) + "是数组中的第" + Str(i) + "个值"
Exit For
End If
Next i
If i > 10 Then
Text2.Text = Str(num) + "不存于数组中"
End If
End Sub
其中的j循环是什么用处
Option Base 1
Dim a(10)
Private Sub Command1_Click()
Text1.Text = "":Text2.Text = ""
For i = 1 To 10
a(i) = Fix(Rnd * 99 + 1)
For j = 1 To i - 1
If a(i) = a(j) Then
i = i - 1
Exit For
End If
Next j
Next i
For i = 1 To 10
Text1.Text = Text1.Text + Str(a(i)) + Space(2)
Next i
End Sub
Private Sub Command2_Click()
Dim num As Integer,i As Integer
num = InputBox("请输入查找的数")
For i = 1 To 10
If a(i) = num Then
Text2.Text = Str(num) + "是数组中的第" + Str(i) + "个值"
Exit For
End If
Next i
If i > 10 Then
Text2.Text = Str(num) + "不存于数组中"
End If
End Sub
其中的j循环是什么用处
▼优质解答
答案和解析
Dim x() As Integer,n As Integer,a As Integer,b As Integer,i As Integer
Private Sub sum()
For i = 1 To n
If x(i) Mod 2 = 0 Then
b = b + x(i)
Else
a = a + x(i)
End If
Next i
End Sub
Private Sub Command1_Click()
n = Val(InputBox("输入整数N"))
ReDim x(n)
Randomize
For i = 1 To n
x(i) = Int(Rnd * 50)
Next i
End Sub
Private Sub Command2_Click()
Call sum
Print "奇数之和=" & a
Print "偶数之和=" & b
End Sub
Private Sub sum()
For i = 1 To n
If x(i) Mod 2 = 0 Then
b = b + x(i)
Else
a = a + x(i)
End If
Next i
End Sub
Private Sub Command1_Click()
n = Val(InputBox("输入整数N"))
ReDim x(n)
Randomize
For i = 1 To n
x(i) = Int(Rnd * 50)
Next i
End Sub
Private Sub Command2_Click()
Call sum
Print "奇数之和=" & a
Print "偶数之和=" & b
End Sub
看了用函数产生10个随机数并保存a...的网友还看了以下:
I have kept touch with sb.keep touch with本意即为和某人保 2020-05-16 …
matlab 关于求偏导数具体值的问题以下是代码:num = 100;for i=1:numa(i 2020-05-16 …
投保平安福终身保障计划时,在险种组合规则上,必须附加( ),且必须以( )的组合形式投保。A、少儿 2020-05-22 …
由s、i、x三个字母和另外两个字母(非s、i、x)组成的五个字母的单词,例如:sixty、sixt 2020-06-02 …
在求保险丝所消耗的热量时,可用公式Q=UU/R*t吗?恩`````那保险丝是纯电阻吗?只能用I*I* 2020-11-03 …
公务员行测逻辑判断政府环保部门的官员若要在这次民间环保研讨会上发言,他就必须是民间环保组织的成员。但 2020-11-08 …
为了增强环境保护意识,6月5日“世界环境日”当大,在环保局工作人员指导下,若干名“环保小卫士”组成的 2020-12-01 …
英语音标问题原音字母i在重读开节中发{ai},即字母音.在重读闭音节中发{i}.i在字母组合igh中 2020-12-04 …
某市“快女”预选中有11个评委,w位歌你的评委分是i.i,i.7,i.7,i.6,i.6,i.6,i 2021-01-02 …
假设有一个投资组合P,xi代表第i项金融资产在投资组合中所占的比例,ri代表第i项金融资产的预期收益 2021-02-19 …