1--35之间任意选5个数字 要求所选的5个数字的和为一个70 把所有可能的都列出来 谢谢了

2025-05-01 18:01:14
推荐回答(1个)
回答1:

Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer = 1
Dim b As Integer = 1
Dim c As Integer = 1
Dim d As Integer = 1
Dim f As Integer = 1
Dim total As Integer = 0
Dim n As Integer = 0 For a = 1 To 35
For b = a To 35
For c = b To 35
For d = c To 35
For f = d To 35
If a + b + c + d + f = 70 Then
total = 70
ListBox1.Items.Add(a & "+" & b & "+" & c & "+" & d & "+" & f & "=" & total)
Console.WriteLine("{0} + {1} + {2} + {3} + {4}= {5}", a, b, c, d, e, total)
n = n + 1
End If
Next Next Next Next Next
End Sub
End Class