VB编写程序:求用inputbox函数输入的十个数的和数和连乘积
1个回答
展开全部
'这个题目有难度
'运行效果如上,代码如下:
Private Sub command1_click()
Dim i As Integer
Dim a, b As Integer
Dim product
product = 1
Dim m As Integer
m = 0
Dim X As String
Dim brr
Dim arr(10)
X = InputBox("请输入10个正整数(以英文逗号分隔):", "求和数与连乘", "例如:3,344,51,12,55,62,8,6,77,1", 1000, 1000)
brr = Split(X, ",")
If UBound(brr) > 9 Then
MsgBox "输入数字多于10个,请重新输入!", , "提醒"
End '退出
End If
If UBound(brr) < 9 Then
MsgBox "输入数字少于10个,请重新输入!", , "提醒"
End '退出
End If
b = 0
For i = 0 To UBound(brr)
product = product * brr(i)
If brr(i) = 1 Then
m = 1 '1既不是质数也不是合数
End If
If brr(i) <> 1 Then '1既不是质数也不是合数
For a = 2 To brr(i) - 1
If brr(i) Mod a = 0 Then
arr(b) = brr(i)
b = b + 1
GoTo S
End If
Next a
End If
S:
Next i
Text1.Text = Join(arr, " ") '合数显示
Text2.Text = product '10个数乘积
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询