楼主 把 VB 和 c 混了 看看这个 Function fun(ByVal n As Integer) As Single Dim i, t As Integer Dim s As Single t = 1 For i = 1 To n t = t * i s = s + 1 / t Next i fun = s End Function 注意,调用 是 n不能太大了,否则 就得 改 dim t as long
你提供的代码有问题,应该如此: Function fun(ByVal n As Integer) As Single Dim i, j, t As Integer:Dim s As Single s=1 for j=2 to n t=1 For i=2 To n t=t*i next i s=s+ 1/t Next j fun= s End Function