用VB编写一个解“数字三角形”程序:将自然数1到6分别填入图中的小圆圈内,使这个三角形的每边上的三个数
2个回答
展开全部
Private Sub Command1_Click()
' 1
' 2 3
' 4 5 6
Dim a(6) As Integer
For i1 = 1 To 6
For i2 = 1 To 6
For i3 = 1 To 6
For i4 = 1 To 6
For i5 = 1 To 6
For i6 = 1 To 6
a(1) = i1
a(2) = i2
a(3) = i3
a(4) = i4
a(5) = i5
a(6) = i6
For i = 1 To 6
For j = i + 1 To 6
If a(i) = a(j) Then GoTo x:
Next
Next
If i1 + i2 + i4 = i4 + i5 + i6 And i1 + i2 + i4 = i1 + i3 + i6 Then
Print " ";
Print i1
Print " ";
Print i2;
Print i3
Print i4;
Print i5;
Print i6
Exit Sub
End If
x:
Next
Next
Next
Next
Next
Next
End Sub
' 1
' 2 3
' 4 5 6
Dim a(6) As Integer
For i1 = 1 To 6
For i2 = 1 To 6
For i3 = 1 To 6
For i4 = 1 To 6
For i5 = 1 To 6
For i6 = 1 To 6
a(1) = i1
a(2) = i2
a(3) = i3
a(4) = i4
a(5) = i5
a(6) = i6
For i = 1 To 6
For j = i + 1 To 6
If a(i) = a(j) Then GoTo x:
Next
Next
If i1 + i2 + i4 = i4 + i5 + i6 And i1 + i2 + i4 = i1 + i3 + i6 Then
Print " ";
Print i1
Print " ";
Print i2;
Print i3
Print i4;
Print i5;
Print i6
Exit Sub
End If
x:
Next
Next
Next
Next
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询