vb 数组题

2020-04-19 10:11发布

<p>2.下列程序是先产生20个不同的随机数,并存于数组a中,然后用比较法(冒泡法)值数据按升序排序输出,请补充完程序。</p><p>Private Sub Form Click()</p><p>Dim a(1 To 20) As Integer, i,j, t, x, yes</p><p>For i=1 To 20</p><p>Do</p><p>x= Int(Rnd *90)+10</p><p>yes=0</p><p>For j=1 To ( 填空1)</p><p>If x= a(j) Then yes =1: Exit For</p><p>Next j</p><p>Loop While (填空2)</p><p>a (i)=(填空3)</p><p>Next i</p><p>For i=1 To 19</p><p>For (填空4) To 20</p><p>If a(i) &gt; a(j) Then (填空5)</p><p>Next j</p><p>Next i</p><p>For i =1 To 20</p><p>Print a(i);</p><p>Next i</p><p>End sub</p><p>&nbsp;</p><p>下面的程序是产生100个[0,99]范围内的随机整数,统计个位上的数字分别为1,2,3,4,5,6,7,8,9,0的数的个数。</p><p>Public Sub Calculate()</p><p>Dim x(1 To 10) As Integer, A(1 To 100)As Integer</p><p>Dim P As Integer, J As Integer</p><p>For J =1 To 100</p><p>A(J)=(填空6)</p><p>P=A(J) - Int(A(J) / 10 )*10</p><p>If P =0 Then (填空7)</p><p>X(P)=X(P)+1</p><p>Next J</p><p>Form1. Print"个位数的个数”</p><p>For J =1 To 10</p><p>(填空8)</p><p>If J =10 Then (填空9)</p><p>Form1. Print "个位数是” &amp;Ps&amp; "有”&amp; X(J) &amp;"有个数"</p><p>Next J</p><p></p><p>End sub</p><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
1条回答

1.程序参考

Private Sub Form_Click()

Dim a(1 To 20) As Integer, i, j, t, x, yes

For i = 1 To 20

Do

x = Int(Rnd * 90) + 10

yes = 0

For j = 1 To 20

If x = a(j) Then yes = 1: Exit For

Next j

Loop While yes = 1

a(i) = x

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

Next j

Next i

For i = 1 To 20

Print a(i);

Next i

End Sub

2。

Public Sub Calculate()

Dim x(1 To 10) As Integer, A(1 To 100) As Integer

Dim P As Integer, J As Integer

For J = 1 To 100

A(J) = Rnd * 100

P = A(J) - Int(A(J) / 10) * 10

If P = 0 Then P = 10

x(P) = x(P) + 1

Next J

Form1.Print "个位数的个数”"

For J = 1 To 10

P = J

If J = 10 Then Ps = 0

Form1.Print "个位数是" & P & "; 有; " & x(J) & "; 有个数; "

Next J

End Sub


一周热门 更多>