趣味数学题。小明使用VB编写程序解一道有趣的数学题:将1到9这九个数字分成三个三位数,不能有重复,三个数字之间比例满足1∶2∶3,求所有三位数组合。
程序界面如图所示,当单击“求解”按钮Command1时,在列表框List1中显示所有满足条件的组合。
程序代码如下,请在划线处填上合适的代码。
Dim a(0 To 9) As Integer
Private Sub Command1_Click()
Dim i, n, m As Integer
For i = 123 To 333
For n = 1 To 9
a(n) = 0
Next n
s = 0
call fenjie (i) ‘使用call调用自定义过程,下同
call fenjie (2 *i)
call fenjie (3 *i)
For m = 1 To 9
s ={#blank#}1{#/blank#}
Next m
If s = 9 Then List1.AddItem i & “ ” & 2 * i & “ ” & 3 * i
Next i
End Sub
Sub fenjie(x As Integer) ‘自定义过程,将3位数分解并修改对应下标元素的值
a(x Mod 10) = 1
{#blank#}2{#/blank#}
a(x \ 100) = 1
End Sub