求VB小程序代码
编写程序求s=1+2!/2+3!/3+...+N!/N)的值输出到一个标签中,N从一个文本框输入...
编写程序求s=1+2!/ 2+3!/3+...+N!/N)的值输出到一个标签中,N从一个文本框输入
展开
展开全部
Private Sub Command1_Click()
If Len(Text1) > 0 And IsNumeric(Text1) And Text1 <> "0" Then
Dim i, s
For i = 1 To Val(Text1)
s = s + fc(i) / i
Next
MsgBox "s=" & s
Else
With Text1
.Text = ""
.SetFocus
End With
End If
End Sub
Private Sub Form_Load()
With Label1
.Caption = ""
.AutoSize = True
End With
Text1 = 3
End Sub
Function fc(n)
Dim i
fc = 1
For i = 1 To n
fc = fc * i
Next
End Function
If Len(Text1) > 0 And IsNumeric(Text1) And Text1 <> "0" Then
Dim i, s
For i = 1 To Val(Text1)
s = s + fc(i) / i
Next
MsgBox "s=" & s
Else
With Text1
.Text = ""
.SetFocus
End With
End If
End Sub
Private Sub Form_Load()
With Label1
.Caption = ""
.AutoSize = True
End With
Text1 = 3
End Sub
Function fc(n)
Dim i
fc = 1
For i = 1 To n
fc = fc * i
Next
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim N As Long
Dim i As Long
Dim j As Long
Dim s As Long
Dim b As Long
N = Val(Text1.Text)
For i = 1 To N
b = 1
For j = 1 To i
b = b * j
Next j
s = s + b / (j - 1)
Next i
Text2.Text = s
End Sub
Dim N As Long
Dim i As Long
Dim j As Long
Dim s As Long
Dim b As Long
N = Val(Text1.Text)
For i = 1 To N
b = 1
For j = 1 To i
b = b * j
Next j
s = s + b / (j - 1)
Next i
Text2.Text = s
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
无语……
N!/N=(N-1)!
N!/N=(N-1)!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询