用vb编写程序,由1.2.3.4四个不同的数字组成的4位整数,要求每行显示十个...
发布网友
发布时间:2024-01-05 01:21
我来回答
共4个回答
热心网友
时间:2024-10-25 23:15
Private Sub Command1_Click()
Dim A As Integer, B As Integer, C As Integer, D As Integer
Dim X As Integer
X = 1
For A = 1 To 4 '千位数循环
For B = 1 To 4 '百位数循环
If B = A Then GoTo S '如果千位数和百位数相等,退出百位数循环
For C = 1 To 4 '十位数循环
If C = B Or C = A Then GoTo P '如果十位数和百位数相等,或十位数和千位数相等,退出十位数循环
For D = 1 To 4 '个位数循环
If D = A Or D = B Or D = C Then '如果个位数和十位数,或个位数和百位数,或个位数和千位数相等,退出个位数循环
GoTo K
Else
Text1.Text = Text1.Text & CStr(A * 1000 + B * 100 + C * 10 + D) & " "
If X Mod 10 = 0 Then Text1.Text = Text1.Text & vbCrLf
X = X + 1
End If
K:
Next D
P:
Next C
S:
Next B
Next A
'这里注意的问题是在判断语句退出循环后,但下一级循环仍然在执行,不是退出整体循环!!
End Sub
热心网友
时间:2024-10-25 23:12
Private Sub Form_Click()
For a = 1 To 4
For b = 1 To 4
If a <> b Then
For c = 1 To 4
If c <> a And c <> b Then
d = 10 - a - b - c
Print a & b & c & d & " ";
e = e + 1
If e Mod 10 = 0 Then Print
End If
Next c
End If
Next b
Next a
Print
End Sub
热心网友
时间:2024-10-25 23:12
Private Sub Command1_Click()
js = 1
For i1 = 1 To 4
For i2 = 1 To 4
If i2 = i1 Then GoTo J1
For i3 = 1 To 4
If i3 = i2 Or i3 = i1 Then GoTo J2
For i4 = 1 To 4
If i4 = i1 Or i4 = i2 Or i4 = i3 Then
GoTo J3
Else
Print i1 & i2 & i3 & i4,
If js Mod 10 = 0 Then Print
js = js + 1
End If
J3:
Next i4
J2:
Next i3
J1:
Next i2
Next i1
End Sub
热心网友
时间:2024-10-25 23:12
Private Sub Form_Click()
Dim n(1 To 4) As Integer, k As Integer, i As Integer
Do
Print n(1) + 1 & n(2) + 1 & n(3) + 1 & n(4) + 1 & " ";
i = i + 1
If i Mod 10 = 0 Then Print
For k = 4 To 1 Step -1
n(k) = n(k) + 1
If n(k) = 4 Then
n(k) = 0
Else
Exit For
End If
Next
Loop Until k = 0
End Sub