用VB求1!+2!+3!+……+10!的结果。

2024-12-13 05:01:25
推荐回答(4个)
回答1:

楼上有几个错误!定义的整型变量数值或溢出,最后一行的标签也输错了!

我已改正,并已运行无误
Private Sub Command1_Click()
Dim i As Integer
Dim sum As Long
Dim n As Long
n = 1
sum = 0
For i = 1 To 10
n = n * i
sum = sum + n
Next
Label1.Caption = sum
End Sub

回答2:

Private Sub Command1_Click()
Dim sum As Long
For i = 1 To 10
sum = sum + JC(i)
Next
Me.Label1.Caption = sum
End Sub

Private Function JC(ByVal i As Integer) As Long
Dim j As Integer, Cj As Long
Cj = 1
For j = 1 To i
Cj = Cj * j
Next
JC = Cj
End Function

回答3:

dim n%,sum%,i%
n = 1
sum = 0
For i = 1 To 10
n = n * i
sum = sum+n
Next
label1.caption=cstr(sum)

回答4:

Dim i As Integer
Dim sum As Integer
Dim n As Integer
n = 1
sum = 0
For i = 1 To 10
n = n * i
sum = sum + n
Next
lebel1.caption=cstr(sum)