用VB求解:输入一个自然数n,求n!,同时统计结果中有多少个0

2024-10-31 02:20:20
推荐回答(2个)
回答1:

Dim n As Long
n = CLng(Text1.Text)
Dim b As Long
Dim m As Long
m = 1
For b = 1 To n
m = m * b
Next b
Print m '显示n!
Dim s As String
Dim s2 As String
s = CStr(m)
s2 = Replace(s, "0", "")
Dim j As Long
j = Len(s) - Len(s2)
Print j '计算结果中0的个数

回答2:

Private Sub Workbook_Open()
Dim n As Integer
Dim i As Integer
Dim m As Integer
n = Cells(1, 2).Value
m = 1
For i = 2 To n
m = m * i
Next
Cells(1, 1).Value = m
End Sub
电脑里面没有装VB,用VBA做了一个,如果你有基础,应该可以自己改进。