VB试题:编写函数fun,函数的功能是:求I 到a之间的偶数之积

VB试题:编写函数fun,函数的功能是:求I 到a之间的偶数之积,第1张

Function fun(a As Double) As Double

a = Int(a)

If a > 1 Then fun = 2

For i = 4 To Int(a / 2) 2 Step 2

fun = fun i

Next

End Function

Function c(a, b As Integer) As Integer

Dim i, j As Integer

j = 0

For i = a To b

j = j + i

Next i

c = j

End Function

Private Sub Form_Load()

Caption = c(1, 100)

End Sub

private sub fun(m as integer) as single

dim i as integer

for i=1 to m

fun=fun+1/(2i)

next

end sub

楼主

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/13492346.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2025-09-01
下一篇2025-09-01

发表评论

登录后才能评论

评论列表(0条)

    保存