
用vb怎么编一个求n!的子过程,然后调用它计算1!+2!-3!
3个回答
展开全部
function sum(n) //n 是你要求的数的阶乘
Dim i As Integer
dim sum as integer
Dim j As Integer
dim t as integer
for i=1 to n step 1
for j=1 to i step 1
t=t*j;
sum=sum+t;
next j
t=0;
next i
print sum;
end function
Dim i As Integer
dim sum as integer
Dim j As Integer
dim t as integer
for i=1 to n step 1
for j=1 to i step 1
t=t*j;
sum=sum+t;
next j
t=0;
next i
print sum;
end function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Function f(x As Integer) As Integer
Dim i, t As Integer
t = 1
For i = 1 To x
t = t * i
Next i
f = t
End Function
Private Sub Form_Click()
Print f(1) + f(2) - f(3)
End Sub
Dim i, t As Integer
t = 1
For i = 1 To x
t = t * i
Next i
f = t
End Function
Private Sub Form_Click()
Print f(1) + f(2) - f(3)
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我用函数给你写一个。过程的,你自己改写一下就行了。
Dim x As Single
Private Function f(sh As Single, n As Integer) As Single
f = sh * x / n
End Function
Private Sub Command1_Click()
Dim e As Single
Dim f0 As Single
Dim n As Integer
Dim jieguo As Single
x = Val(InputBox("请输入自变量:"))
Do
e = Val(InputBox("请输入允许误差(0<e<0.00005):"))
Loop Until e > 0 And e < 0.00005
jieguo = 1
n = 1
f0 = 1
Do
f0 = f(f0, n)
jieguo = jieguo + f0
n = n + 1
Loop Until f0 < e
Print jieguo
End Sub
界面就放一只按钮。
Dim x As Single
Private Function f(sh As Single, n As Integer) As Single
f = sh * x / n
End Function
Private Sub Command1_Click()
Dim e As Single
Dim f0 As Single
Dim n As Integer
Dim jieguo As Single
x = Val(InputBox("请输入自变量:"))
Do
e = Val(InputBox("请输入允许误差(0<e<0.00005):"))
Loop Until e > 0 And e < 0.00005
jieguo = 1
n = 1
f0 = 1
Do
f0 = f(f0, n)
jieguo = jieguo + f0
n = n + 1
Loop Until f0 < e
Print jieguo
End Sub
界面就放一只按钮。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |