Dim 猛饥伏p As Long, n As 肢桥Integer, i As Integer
p = 1
n = Val(InputBox("input n", , 5))
For i = 枝携1 To n
p = p * i
Next
Print p
End Sub
Public Function jiecheng(ByVal n As Integer) As DoubleDim jc As Double
jc = 1
敏禅 For i = 1 To n
jc = jc * i
Next
jiecheng = jc
End Function
2、具体用法:首先打开VB6.0,新建一个标准exe工程;
3、在设计界面上添加一个Command控件,Command1的Caption属性设置为"N的阶乘"。
4、双击Command1控件进入代码编辑界面,编辑代码态扮如下:
Public Function jiecheng(ByVal n As Integer) As DoubleDim jc As Double
jc = 1
For i = 1 To n
jc = jc * i
Next
帆拿灶 jiecheng = jc
End Function
Private Sub Command1_Click()
Dim sum As Double, n As Integer
n = InputBox("计算的N的阶乘,请输入数字N")
sum = jiecheng(n)
MsgBox (sum)
End Sub
5、运行新建的工程,单击按钮,输入要计算的N的阶乘的数字N,得出阶乘结果。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)