编写vb程序,求s=a!+b!+c!,阶乘的计算用sub过程方法实现,谢谢
3个回答
展开全部
sub是没有返回值的。在这里我用function举个例吧。。如果用sub的话就只能用控件显示或许用msgbox
function jiecheng(byval n as single)
s=1
for i=1 to n
s=s*n
next
jiecheng=s
end function
sub sum(a,b,c)
msgbox jiecheng (a)+jiecheng(b)+jiecheng(c)
end sub
或者传引用也行
sub jiecheng(byref n as single)byref可以省略
s=1
for i=1 to n
s=s*n
next
n=s
end sub
function jiecheng(byval n as single)
s=1
for i=1 to n
s=s*n
next
jiecheng=s
end function
sub sum(a,b,c)
msgbox jiecheng (a)+jiecheng(b)+jiecheng(c)
end sub
或者传引用也行
sub jiecheng(byref n as single)byref可以省略
s=1
for i=1 to n
s=s*n
next
n=s
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
多次调用函数问题
Private Sub Command1_Click()
Dim a As Long, b As Long, c As Long
a = Val(InputBox("输入a", "提示"))
b = Val(InputBox("输入b", "提示"))
c = Val(InputBox("输入c", "提示"))
Dim r as Long
r=Multiply(a)+Multiply(b)+Multiply(c)
Print r
End Sub
Private Function Multiply(n As Long) As Long
Dim x As Long
Multiply = 1
For x = 1 To n
Multiply = Multiply * x
Next
End Function
Private Sub Command1_Click()
Dim a As Long, b As Long, c As Long
a = Val(InputBox("输入a", "提示"))
b = Val(InputBox("输入b", "提示"))
c = Val(InputBox("输入c", "提示"))
Dim r as Long
r=Multiply(a)+Multiply(b)+Multiply(c)
Print r
End Sub
Private Function Multiply(n As Long) As Long
Dim x As Long
Multiply = 1
For x = 1 To n
Multiply = Multiply * x
Next
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询