作业帮 > 数学 > 作业

用VB程序编写 和数能表示1到23的5个正整数

来源:学生作业帮 编辑:拍题作业网作业帮 分类:数学作业 时间:2024/04/29 04:24:48
用VB程序编写 和数能表示1到23的5个正整数
Private Sub Command1_Click()
Dim c() As Variant
Dim e As Boolean
'预设五个最小的正整数为1、2、3、4、5
For i = 3 To 11 '由题意可得第一第二个正整数必然等于1和2,第三个数最小为3,最大为23-1-2-4-5=11
For j = i + 1 To 12 '假如第三个数为3,最小的第四个数为4,最大值为23-1-2-3-5=12
For n = j + 1 To 13 '假如第四个数为4,最小的第五个数为5,最大值为23-1-2-3-4=13
If 1 + 2 + i + j + n = 23 Then
c = Array(1, 2, i, j, n, 1 + 2, 1 + i, 1 + j, 1 + n, 1 + i + j, 1 + i + n, 1 + j + n, 1 + i + j + n, 2 + i, 2 + j, 2 + n, 2 + i + j, 2 + i + n, 2 + j + n, 2 + i + j + n, 3 + i, 3 + j, 3 + n, 3 + i + j, 3 + i + n, 3 + j + n, 3 + i + j + n, i + j, i + n, i + j + n, j + n)
For l = 1 To 23
For k = 0 To UBound(c)
e = False
If c(k) = l Then e = True: Exit For
Next
If e = False Then Exit For
Next
If e = True Then Print "符合条件的有:1+2+" & i & "+" & j & "+" & n
End If
Next
Next
Next
End Sub希望没错