概述
1.打开VB6.0
2.窗体上插入一command button,双击并输入代码:
代码一
Private Sub Command1_Click()
Dim i As Integer
Dim a(10) As Integer
Randomize
For i = 1 To 10
a(i) = Int(Rnd * 1000) + 1
Sum = Sum + a(i)
Next i
Print Sum
End Sub
代码二
Private Sub Command1_Click()
Cls
Dim n As Integer, s As Integer
Dim 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
代码三
Private Sub Command1_Click()
Dim i As Integer
Dim a As Integer
Sum = 0
For i = 1 To 10
Randomize
a = Int(1000 * Rnd)
Sum = Sum + a
MsgBox “10个随机数之和为:” & Sum
Next
End Sub
代码四
Private Sub Command1_Click()
Cls
Font.Size = 70
Print f(100)
End Sub
Private Function f(x As Integer) As Long
If x = 1 Then
f = x
Else
f = x + f(x - 1)
End If
End Function
最后
以上就是纯真麦片为你收集整理的15电气李丹【10个随机数求和】的全部内容,希望文章能够帮你解决15电气李丹【10个随机数求和】所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复