1--35之间任意选5个数字 要求所选的5个数字的和为一个70 把所有可能的都列出来 谢谢了
- 提问者网友:两耳就是菩提
- 2021-04-12 14:26
- 五星知识达人网友:青尢
- 2021-04-12 15:12
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
- 1楼网友:舊物识亽
- 2021-04-12 16:36
VB不会 给你个思路吧
70/5=14
所以肯定有比14大 和 14小的
所以前三个数 做个三重循环再1-14里取
后两个数 就在15-25 中选
也做个一次循环 用剩余值的差来做判断条件就可以了
- 2楼网友:青尢
- 2021-04-12 16:13