看图片进行编写VB当输入n为奇数时
Sub main()
Dim sum!, n%
腊厅蚂伏晌 i = 5
Do
n = InputBox("")
If n > 1 Then Exit Do
Loop
If n Mod 2 = 0 Then
Debug.Print "even=";
sum = dcall("peven", n)
Else
Debug.Print "odd=";
sum = dcall("podd", n)
End If
Debug.Print sum
End Sub
Function peven!(ByVal n%)
Dim s!, i%
s = 1
For i = 2 To n Step 2
s = s + 1 轮埋/ i
Next
peven = s
End Function
Function podd!(ByVal n%)
Dim s!, i%
s = 0
For i = 1 To n Step 2
s = s + 1 / i
Next
podd = s
End Function
Function dcall(ByVal s$, ByVal n%)
If s = "peven" Then
dcall = peven(n)
ElseIf s = "podd" Then
dcall = podd(n)
End If
End Function