任意十个数求和

打开VB,在form窗口中创建command的图标,然后双击图标;

输入以下代码:

Private Sub Command1_Click()
Cls
Dim n As Integer, s As Integer, a(10) As Integer
n = 1
While n <= 10
a(n) = Int(Rnd * 1000)
n = n + 1
Wend
n = 1
While n <= 10
Print a(n)
n = n + 1
Wend
s = 0
n = 1
While n <= 10
s = s + a(n)
n = n + 1
Wend
Print “和为”; s
End Sub

你可能感兴趣的:(任意十个数求和)