VB有一个三位数abc和a 的积为一个四位正整数baac,编程求这一个三位数
问题描述:
VB有一个三位数abc和a 的积为一个四位正整数baac,编程求这一个三位数
答
Dim a As Integer, b As Integer, c As Integer
For a = 1 To 9 '首位 a 不可能为 0,故从1开始
For b = 0 To 9
For c = 0 To 9
If (a * 100 + b * 10 + c) * a = (b * 1000 + a * 100 + a * 10 + c) Then
Print a * 100 + b * 10 + c
End If
Next c
Next b
Next a
End Sub
用穷举法穷举即可,同学要努力.
Private Sub Command1_Click()Dim a As Integer, b As Integer, c As Integer
For a = 1 To 9 '首位 a 不可能为 0,故从1开始
For b = 0 To 9
For c = 0 To 9
If (a * 100 + b * 10 + c) * a = (b * 1000 + a * 100 + a * 10 + c) Then
Print a * 100 + b * 10 + c
End If
Next c
Next b
Next a
End Sub