VB中怎么求N!
答案:4 悬赏:0
解决时间 2021-02-05 04:00
- 提问者网友:他是我的あ男人
- 2021-02-04 06:47
VB中怎么求N!
最佳答案
- 二级知识专家网友:留下所有热言
- 2021-02-04 07:47
function factorial(byval n as integer) as integer
if n>1 then
factorial=n*factorial(n-1)
else
factorial=factorial
end if
end function
'此方法缺陷(n:1~12)
if n>1 then
factorial=n*factorial(n-1)
else
factorial=factorial
end if
end function
'此方法缺陷(n:1~12)
全部回答
- 1楼网友:爱情是怎么炼成的
- 2021-02-04 09:46
Private Sub command_click()
Dim i as integer
counst s=1
a=inputbox("输入数字N")
for i=1 To a step 1
s=s*i
next
label1.caption= s
End Sub
- 2楼网友:苦柚恕我颓废
- 2021-02-04 09:05
Option Explicit
Dim N As Double
Private Function fact(N As Integer) As Double
fact = 1
Do While N > 0
fact = fact * N
N = N - 1
Loop
End Function
Private Sub Command1_Click()
Text2 = fact(Val(Text1))
End Sub
Private Sub Form_Load()
Text1 = 1: Text2 = ""
End Sub
- 3楼网友:孤伤未赏
- 2021-02-04 08:05
Private Sub Form_Click()
n = InputBox("输入N的值")
s = 1
For i = 1 To n
s = s * i
Next
Print n & "的阶乘为:" & s
End Sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯