“求1到10的阶乘之和”用VB怎么编程序
1x2x4x6x8x10------+---------+-----------1!2!4!6!8!10!谢谢大家.请大家帮帮忙了...
1 x2 x4 x6 x8 x10
-- - --- + ---- - ---- + ------ - ----
1! 2! 4! 6! 8! 10!
谢谢大家.请大家帮帮忙了 展开
-- - --- + ---- - ---- + ------ - ----
1! 2! 4! 6! 8! 10!
谢谢大家.请大家帮帮忙了 展开
2个回答
展开全部
'先写一个求阶乘的函数
Private Function factorial(ByVal n As Integer) As Long
Dim i As Integer, l As Long
l = 1
For i = 1 To n
l = l * i
Next
factorial = l
End Function
'添加一个按钮控件
Private Sub Command1_Click()
Dim result As Long, i As Integer
result = 0
For i = 1 To 10
result = result + factorial(i)
Next
Form1.Print result
End Sub
'结果为4037913
Private Function factorial(ByVal n As Integer) As Long
Dim i As Integer, l As Long
l = 1
For i = 1 To n
l = l * i
Next
factorial = l
End Function
'添加一个按钮控件
Private Sub Command1_Click()
Dim result As Long, i As Integer
result = 0
For i = 1 To 10
result = result + factorial(i)
Next
Form1.Print result
End Sub
'结果为4037913
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
结果 22.2186507936508
Option Explicit
Private Function factorial(ByVal n As Long) As Double
Dim i As Long
Dim L As Double
For i = 1 To n
L = L + 1 / i
Next
factorial = L
End Function
Private Sub Command1_Click()
Dim result As Double, i As Long
result = 0
For i = 1 To 10
result = result + factorial(i)
Next
Debug.Print result
End Sub
Option Explicit
Private Function factorial(ByVal n As Long) As Double
Dim i As Long
Dim L As Double
For i = 1 To n
L = L + 1 / i
Next
factorial = L
End Function
Private Sub Command1_Click()
Dim result As Double, i As Long
result = 0
For i = 1 To 10
result = result + factorial(i)
Next
Debug.Print result
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询