第四章第二次
1.Private Function jiecheng(n As Integer) As Long
Dim n As Long
n = 1
For i = 1 To n
n = n * i
Next
jiecheng = n
End Function
Private Sub Command1_Click()
Dim sum As Long
Dim i As Integer
sum = 0
For i = 1 To 10
sum = sum + jiecheng(i)
Next
Text1.Text = sum
End Sub
2.
Private Sub Command1_Click()
Dim s As Integer
Dim m As Integer
Dim n As Integer
s = Text1.Text
For m = 3 To s / 2
If sushu(m) And sushu(s - m) Then
Text2.Text = m
Text3.Text = s - m
Exit For
End If
Next
End Sub
Private Function sushu(x As Integer) As Boolean
If x = 1 Then
sushu = False
Else
If x = 2 Then
sushu = True
Else
For n = 2 To x / 2
If x Mod n = 0 Then
Exit For
End If
Next
If n > x / 2 Then
sushu = True
Else
sushu = False
End If
End If
End If
End Function
3.
Private Sub sum(m As Integer, n As Integer, ByRef s As Double)
Dim i As Integer
Dim sum As Double
sum = 0
For i = 1 To n
sum = sum + mi(m, i) / jiecheng(i)
Next
s = sum
End Sub
Private Function mi(m As Integer, n As Integer) As Long
mi = 1
For i = 1 To n
mi = m * mi
Next
End Function
Private Function jiecheng(n As Integer) As Long
Dim prod As Long
prod = 1
For i = 1 To n
prod = prod * i
Next
jiecheng = prod
End Function
Private Sub Command1_Click()
Dim m%, n%, y As Double
m = 2: n = 10
Call sum(m, n, y)
Text1.Text = y
End Sub

0 条评论:
发表评论
订阅 博文评论 [Atom]
<< 主页