问一道VB的编程题

来源:百度知道 编辑:UC知道 时间:2024/06/06 16:43:34
题目要求:求一个四位自然数
1.是11的倍数
2.十位数和百位数的和等于千位数
3.百位数和十位数组成的两位自然数为完全平方数
4.四位数的各位数字互不相同

我的代码

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim n, m As Integer
Dim a, b, c, d As Integer
For n = 1000 To 9999
a = n / 1000
b = (n - a * 1000) / 100
c = (n - a * 1000 - b * 100) / 10
d = n - a * 1000 - b * 100 - c * 10
Do While n Mod 11 = 0
Do While b + c = a
For m = 4 To 9
Do While b * 10 + c = m * m
Do While a <> b And b <> c And c <> d And d <> b And c <> a And a <> d
Loop
Loop
Next
Loop

Loop
<

Dim i%

For i = 1000 To 9999
If Sqr((i Mod 1000) \ 10) = Fix(Sqr((i Mod 1000) \ 10)) Then '百和十位是完全平方数
If (i \ 100 Mod 10) + (i \ 10 Mod 10) = i \ 1000 Then '百和十位和是千位
If i Mod 11 = 0 Then '是11的倍数
If Len(Replace(CStr(i), Mid(CStr(i), 1, 1), "")) = 3 Then
If Len(Replace(CStr(i), Mid(CStr(i), 2, 1), "")) = 3 Then
If Len(Replace(CStr(i), Mid(CStr(i), 3, 1), "")) = 3 Then
If Len(Replace(CStr(i), Mid(CStr(i), 4, 1), "")) = 3 Then
Print i
End If
End If
End If
End If
End If
End If
End If
Next