vb编程:随机产生10个1到20之间的整数,放在数组A中,然后将A的元素倒序存放,即第一个变为最后

vb编程:随机产生10个1到20之间的整数,放在数组A中,然后将A的元素倒序存放,即第一个变为最后一个,第二个变为倒数第二个。

Private Sub Command1_Click()

  Dim a(10) As Integer

  Randomize

  Print "原来的数:"

  For i = 1 To 10

    a(i) = Int(Rnd * 20) + 1

    Print a(i);

  Next i

  Print

  Print "交换以后的数:"

  i = 1: j = 10

  Do While i < j

    t = a(i): a(i) = a(j): a(j) = t

    i = i + 1: j = j - 1

  Loop

  For i = 1 To 10

    Print a(i);

  Next i

  Print: Print

End Sub

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-07-16
Private Sub Form_click() '单击窗体
Dim a(1 To 10)
Randomize
Print "原数组:";
For i = 1 To 10
a(i) = Int(Rnd * 20 + 1)
Print a(i); " ";
Next
Print
Print "调换后:";
For i = 1 To 5
t = a(i)
a(i) = a(11 - i)
a(11 - i) = t
Next
For i = 1 To 10
Print a(i); " ";
Next
End Sub

双击窗体 打开代码窗口 清楚里面所有内容 复制上面代码进去~ 按F5运行 点击窗体 显示效果本回答被网友采纳
第2个回答  2014-07-16
Option Base 1
Private Sub Command1_Click()
Dim s(10) As Integer
For i = 1 To 10
s(i) = Rnd() * 10+10
Print s(i)
Next i
Print "以上是初始的10个随机整数"
For a = 10 To 1 Step -1
Print s(a)
Next a
Print "以上逆转顺序后的10个随机整数"
End Sub追问

请问用vb怎么编程?

追答

你刚学吗?

追问

嗯嗯

嗯嗯

追答

以前学过其他的没

追问

没有

追答

你还是多看看网上的教程,买本书,理解其中的规则

你还是多看看网上的教程,买本书,理解其中的规则

vb编程:随机产生10个1到20之间的整数,放在数组A中,然后将A的元素倒序...
Randomize Print "原来的数:"For i = 1 To 10 a(i) = Int(Rnd * 20) + 1 Print a(i);Next i Print Print "交换以后的数:"i = 1: j = 10 Do While i < j t = a(i): a(i) = a(j): a(j) = t i = i + 1: j = j - 1 Loop For i = 1 To 10 Print ...

vb单击“数列生成”按钮,自动生成10个10~90之间的随机整数,存于...
Dim a(1 To 10) As IntegerPrivate Sub Command1_Click() List1.Clear Randomize (Timer) For i = 1 To 10 a(i) = Int(Rnd(i) * 81 + 10) List1.AddItem a(i) Next iEnd SubPrivate Sub Command2_Click() List2.Clear For i = 1 To 9 For j = i + 1 ...

vb编程输入10个整数存入一维数组,再按逆序重新存放后再输出?
Dim a(10) As Integer Print "初始的数:"For i = 1 To 10 a(i) = InputBox("请输入第" & i & "个数:")Print a(i);Next i Print For i = 1 To 5 t = a(i)a(i) = a(11 - i)a(11 - i) = t Next i Print "逆序重新存放后的数:"For i = 1 To 10 Print ...

vb利用随机函数产生10个两位数素数,存到数组a中,要求数组元素互不相同...
Dim a(10), x As Integer Dim str As String = "" Dim di As Boolean = True Dim n As Integer For i = 1 To 10 Do Do n = Int(Rnd() * 1000 + 10) Loop Until IsSushu(n) If i > 1 Then For x = 1 To i - 1 ...

用VB编写程序,随机产生10个二位数,放入数组A中,从中选出一个最大的和...
Private Sub Command1_Click() Randomize Dim a(9) As Integer, intMax As Integer, intMin As Integer intMax = 0: intMin = 100 Print "Array:"; For i = 0 To 9 a(i) = Int(Rnd * 90 + 10) Print a(i); If a(i) > intMax Then intMax = a(i) ...

VB怎么写随机生成10个[1,100]之间的数,并从大到小排列的程序?
Dim a(10)x = Rnd '第一个随机数总是2 Randomize Timer '找出随机数 'For i = 1 To 10 a(i) = Fix(1 + ((100 - 1 + 1) * Rnd)) '公式:Fix(m + (n-m+1 * Rnd))Randomize Timer Next i ''排序 For i = 1 To 10 - 1 For j = i + 1 To 10 If a(i) > ...

vb编程:随机产生10个1–100之间的整数,并按从小到大顺序输出,谁能帮我...
a(10), i, j As Integer For i = 0 To 9 a(i) = Int(Rnd * 100) + 1 Print a(i);Next For i = 0 To 8 For j = i To 9 If a(i) > a(j) Then t = a(i)a(i) = a(j)a(j) = t End If Next Next Print For i = 0 To 9 Print a(i)Next End Sub ...

用VB编程:随机产生10个0~100之间的随机整数,存放在一个数组中,然后求个...
a(i) = Int(Rnd(1) * 101)x = x + a(i)Next i Print "元素和=" & x Print "平均值=" & x \/ 10 For i = 0 To 9 If a(i) > (x \/ 10) Then j = j + 1: y = y & CStr(a(i)) & " "Next i Print "大于平均值的元素个数=" & j Print "大于平均值的...

用VB写 有一个数组,内放10个整数,要求找出最小的数及其下标,然后把它...
Dim a(10) As Integer Dim t As Integer Dim n As Integer t = 200 For i = 1 To 10 a(i) = Int(Rnd * 90 + 10) If a(i) < t Then t = a(i) n = i End If Print a(i); Next i Print If n <> 1 Then a(n) = a(...

...用数组保存随机产生的10个介于20到50之间的整数,编程求出其中的最...
Randomize Dim a(1 To 10)Dim max, min, ave min = 50: max = 20 For i = 1 To 10 a(i) = Int(Rnd * 21 + 30)Print a(i);If max < a(i) Then max = a(i)If min > a(i) Then min = a(i)ave = ave + a(i)Next i ave = ave \/ 10 Print Print " 最大值"...

相似回答