又来了
这周事情好多
抽时间写VB
老实说
VB课上的内容没怎么听懂
特别是for each t in a的那种方法
实在是运行不出来
下面就说说我运行出来的算15个数和的几种方法
方法1:
具体程序为:
Option Explicit
Private Sub Command1_Click()
Cls
Font.Size = 70
Dim i As Integer
Dim a(10) As Integer
Dim sum As Integer
Randomize
Fori = 1 To 10
a(i)= Int(Rnd * 1000)
sum= sum + a(i)
Next i
Print sum
End Sub
方法二:
具体程序为:
Private Sub Command1_Click()
Cls
Font.Size = 30
Dim n As Integer
Dim 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
方法三:
具体程序为:
Dim i As Integer
Dim a As Integer
Dim sum As Integer
Private Sub Command1_Click()
Cls
Font.Size = 30
sum = 0
For i = 1 To 10
Randomize
a =Int(Rnd * 1000)
sum= sum + a
Print "10个随机数和为:" & sum
Next
End Sub
方法四:
具体程序为:
Dim i As Integer
Dim a As Integer
Dim sum As Integer
Private Sub Command1_Click()
Cls
Font.Size = 30
sum = 0
i = 1
Do While i <= 10
Randomize
a = Int(Rnd * 1000)
sum = sum + a
MsgBox "10个随机数和为:"& sum
Loop
End Sub
方法五:
具体程序为:
Dim i As Integer
Dim a As Integer
Dim sum As Integer
Private Sub Command1_Click()
Cls
Font.Size = 30
sum = 0
Do Until i > 10
Randomize
a = Int(Rnd * 1000)
sum = sum + a
MsgBox "10个随机数和为:"& sum
Loop
End Sub
方法六:
具体程序为:
Dim i As Integer
Dim a As Integer
Dim sum As Integer
Private Sub Command1_Click()
Cls
Font.Size = 30
sum = 0
i = 1
Do
Randomize
a =Int(Rnd * 1000)
sum= sum + a
i =i + 1
Loop While i <= 10
MsgBox "10个随机数和为:"& sum
End Sub
方法七:
具体程序为:
Private Sub Command1_Click()
Cls
Font.Size = 70
Print f(10)
End Sub
Private Function f(x As Integer) As Long
Ifx = 1 Then
f= x
Else
f= x + f(x - 1)
EndIf
End Function
方法八:
具体程序为:
Private Sub Command1_Click()
Cls
Font.Size = 70
Dim i As Integer
Dim a As Integer
Dim sum As Integer
Do
Randomize
a = Int(Rnd* 1000)
sum= sum + a
i =i + 1
Loop Until i > 10
MsgBox "10个随机数和为:"& sum
End Sub
方法九:
这就是我前面说的for each那个
运行不出来阿
Private Sub Command1_Click()
Cls
Font.Size = 30
Dim n As Integer
Dim 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
Dim t As Integer
For Each t In a
s = s + t
Next
Print s
End Sub
依稀觉得好像哪里错了....
但是又找不出来错
好了
以上就是15个数和的方法
走拉