关于VB求解题目的问题

2024-12-26 08:56:31
推荐回答(3个)
回答1:

这一串“1232525610”是10位数,不是9位数
修改了下,有修改的地方有加注释

Private Sub Command2_Click()
Dim a, b, c, d, e, f, g, h, i, x As Long
For a = 1 To 9 Step 1
For b = 0 To 8 Step 2
If (10 * a + b) Mod 2 = 0 Then
For c = 2 To 9 Step 1
If (100 * a + 10 * b + c) Mod 3 = 0 Then
For d = 0 To 8 Step 2
If (1000 * a + 100 * b + 10 * c + d) Mod 4 = 0 Then
For e = 0 To 5 Step 5
If (10000 * a + 1000 * b + 100 * c + 10 * d + e) Mod 5 = 0 Then
For f = 0 To 8 Step 2
If (100000 * a + 10000 * b + 1000 * c + 100 * d + 10 * e + f) Mod 6 = 0 Then
For g = 1 To 9 Step 1
If (1000000 * a + 100000 * b + 10000 * c + 1000 * d + 100 * e + 10 * f + g) Mod 7 = 0 Then
For h = 0 To 8 Step 2
If (10000000 * a + 1000000 * b + 100000 * c + 10000 * d + 1000 * e + 100 * f + 10 * g + h) Mod 8 = 0 Then
For i = 1 To 9 Step 1
If (100000000 * a + 10000000 * b + 1000000 * c + 100000 * d + 10000 * e + 1000 * f + 100 * g + 10 * h + i) Mod 9 = 0 Then
x = 100000000 * a + 10000000 * b + 1000000 * c + 100000 * d + 10000 * e + 1000 * f + 100 * g + 10 * h + i
Text1.Text = Text1.Text & " " & x & "" '添加了这一句
End If
Next i
End If
Next h
End If
Next g
End If
Next f
End If
Next e
End If
Next d
End If
Next c
End If
Next b
Next a
'Text1.Text = "" & x & "" '注释此句
End Sub

纠正:
Dim a, b, c, d, e, f, g, h, i, x As Long
其中只有是变量x是Long类型,其他的均为变体类型,可以用函数VarType()验证

希望回答对你有帮助。

回答2:

Option Explicit

Private Sub Command1_Click()
Dim a%(1 To 9)
Dim b(0 To 9) As Long
Dim i%, j%, k%
For i = 1 To 9: a(i) = 0: Next i: a(1) = 1: b(0) = 0
i = 1
Do
b(i) = b(i - 1) * 10 + a(i)
If b(i) Mod i = 0 And InStr(1, b(i), a(i)) = i Then
i = i + 1
Else
a(i) = a(i) + 1
End If
If i < 10 Then
If a(i) > 9 Then a(i) = 0: i = i - 1: a(i) = a(i) + 1
Else
List1.AddItem b(i - 1): i = i - 1: a(i) = a(i) + 1
End If
If a(1) > 10 Then Exit Do
Loop While i < 10
Text1 = "": For i = 0 To List1.ListCount: Text1 = Text1 & List1.List(i) & vbCrLf: Next i
End Sub

381654720
381654729
783204165
801654723

回答3:

文本框拉大,多行属性(MultiLine)变成true
Text1 = Text1 + " " + Str(x)放在x=..下边
x = 100000000 * a + 10000000 * b + 1000000 * c + 100000 * d + 10000 * e + 1000 * f + 100 * g + 10 * h + i
Text1 = Text1 + " " + Str(x)

时间会有点长,等吧...
ynzsvt 的是个好办法,不过最好还是输出到文本.快点...