vb 求 1×2×3×.×99×100=Private Sub Form_Click()Dim i As IntegerDim sum As Integersum = 1For i = 1 To 100 Step 1sum = sum * iNext iEnd Sub 这个有什么问题啊?

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 03:39:37

vb 求 1×2×3×.×99×100=Private Sub Form_Click()Dim i As IntegerDim sum As Integersum = 1For i = 1 To 100 Step 1sum = sum * iNext iEnd Sub 这个有什么问题啊?
vb 求 1×2×3×.×99×100=
Private Sub Form_Click()
Dim i As Integer
Dim sum As Integer
sum = 1
For i = 1 To 100 Step 1
sum = sum * i
Next i
End Sub
这个有什么问题啊?

vb 求 1×2×3×.×99×100=Private Sub Form_Click()Dim i As IntegerDim sum As Integersum = 1For i = 1 To 100 Step 1sum = sum * iNext iEnd Sub 这个有什么问题啊?
sum定义为整型肯定会溢出的
必须定义为double
Private Sub CommandButton1_Click()
Dim i As Integer
Dim sum As Double
sum = 1
For i = 1 To 100 Step 1
sum = sum * i
Next i
TextBox1.Text = sum
End Sub