VB程序中怎么求阶乘?

应该是这个图
2024-12-27 04:49:05
推荐回答(3个)
回答1:

Private Sub Command1_Click()
Dim i, b As Integer
Dim a As Double
a = 1
For i = 1 To b
a = i * a
Next i
'a为b的阶乘
Text1.Text = a
End Sub

回答2:

Private Sub Command1_Click()
Dim i%, n%, s&
s = 1
For i = 1 To 3
If CallByName(Me, "Option" & i, VbGet).Value Then n = i + 9: Exit For
Next
For i = 1 To n
s = s * i
Next
Text1 = s
End Sub

回答3:

Dim n As Integer
Private Sub Command1_Click()
Dim i, t As Long
t = 1
For i = 1 To n
t = t * i
Next i
Text1.Text = t
End Sub

Private Sub Option1_Click()
n = 10
End Sub

Private Sub Option2_Click()
n = 11
End Sub

Private Sub Option3_Click()
n = 12
End Sub