请教高手一个VB算法的问题
用VB写个算abcd*f=dcba,a,b,c,d,f为1到9的任意数,但不能重复请把代码写下,给分,谢谢!!!...
用VB写个算abcd*f=dcba,a,b,c,d,f为1到9的任意数,但不能重复
请把代码写下,给分,谢谢!!! 展开
请把代码写下,给分,谢谢!!! 展开
4个回答
展开全部
Private Sub Command1_Click()
Dim a As Double, b As Double, c As Double, d As Double, f As Double, m As Double, n As Double
For a = 1 To 9
For b = 1 To 9
For c = 1 To 9
For d = 1 To 9
For f = 1 To 9
m = (a * 1000 + b * 100 + c * 10 + d) * f
n = d * 1000 + c * 100 + b * 10 + a
If m = n And a <> b And a <> c And a <> d And b <> c And b <> d And c <> d Then
Print "a="; a, "b="; b, "c="; c, "d="; d
End If
Next f
Next d
Next c
Next b
Next a
End Sub
计算结果是:2178 f=4
Dim a As Double, b As Double, c As Double, d As Double, f As Double, m As Double, n As Double
For a = 1 To 9
For b = 1 To 9
For c = 1 To 9
For d = 1 To 9
For f = 1 To 9
m = (a * 1000 + b * 100 + c * 10 + d) * f
n = d * 1000 + c * 100 + b * 10 + a
If m = n And a <> b And a <> c And a <> d And b <> c And b <> d And c <> d Then
Print "a="; a, "b="; b, "c="; c, "d="; d
End If
Next f
Next d
Next c
Next b
Next a
End Sub
计算结果是:2178 f=4
展开全部
做个循环就行吧。好麻烦啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a, b, c, d, f As Integer
Private Sub Form_Load()
For a = 1 To 9
For b = 1 To 9
For c = 1 To 9
For d = 1 To 9
For f = 1 To 9
If a <> b And b <> c And a <> c And a <> d And b <> d And c <> d And a <> f And b <> f And c <> f And d <> f Then
If (1000 * a + 100 * b + 10 * c + d) * f = 1000 * d + 100 * c + 10 * b + a Then
Print a & b & c & d; "x"; f
End If
End If
Next f, d, c, b, a
End Sub
Private Sub Form_Load()
For a = 1 To 9
For b = 1 To 9
For c = 1 To 9
For d = 1 To 9
For f = 1 To 9
If a <> b And b <> c And a <> c And a <> d And b <> d And c <> d And a <> f And b <> f And c <> f And d <> f Then
If (1000 * a + 100 * b + 10 * c + d) * f = 1000 * d + 100 * c + 10 * b + a Then
Print a & b & c & d; "x"; f
End If
End If
Next f, d, c, b, a
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
For i = 1 To 4 'f不可能等于1,至少为2,故a至多为4
For j = 1 To 9
For k = 1 To 9
For m = 1 To 9
For n = 1 To 8
If i <> j And i <> k And i <> m And j <> k And j <> m And k <> m And n <> i _
And n <> j And n <> k And n <> m Then
a = (1000 * i + 100 * j + 10 * k + m) * n
b = 1000 * m + k * 100 + j * 10 + i
If a = b Then
Print i, j, k, m, n
Exit Sub
End If
End If
Next
Next
Next
Next
Next
End Sub
For i = 1 To 4 'f不可能等于1,至少为2,故a至多为4
For j = 1 To 9
For k = 1 To 9
For m = 1 To 9
For n = 1 To 8
If i <> j And i <> k And i <> m And j <> k And j <> m And k <> m And n <> i _
And n <> j And n <> k And n <> m Then
a = (1000 * i + 100 * j + 10 * k + m) * n
b = 1000 * m + k * 100 + j * 10 + i
If a = b Then
Print i, j, k, m, n
Exit Sub
End If
End If
Next
Next
Next
Next
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询