写四个VB算法
1、 取1元、2元、5元纸币共10张,使其总和为24元,用流程图描述、并用VB写出算法。
2、 包装600个变形金刚,要求:
(1)包装的规格分别是:小盒(每盒2个)、中盒(每盒5个)和大盒(每盒8个);
(2)每种规格的盒数都不能为0。
用VB设计此算法。
3、试设计一个算法实现下图的打印
*
**
***
****
4、用VB写一个算法,列举出100以内的所有勾股数。
参考答案:1.Private Sub Command1_Click()
Const a As Integer = 1, b As Integer = 2, c As Integer = 5
Dim p As Integer, q As Integer, r As Integer
For p = 0 To 10
For q = 0 To 10
For r = 0 To 4
If p + q + r = 10 Then
If p * a + q * b + r * c = 24 Then
Print "一元钱的张数是" & p & " " & " 2元钱的张数是" & q & " " & "5元钱的张数是" & r
End If
End If
Next r
Next q
Next p
End Sub
等一下再给你发.
2.Private Sub Command1_Click()
Const a As Integer = 2, b As Integer = 5, c As Integer = 8
Dim p As Integer, q As Integer, r As Integer
For p = 1 To 299
For q = 1 To 119
For r = 1 To 74
If p * a + q * b + r * c = 600 Then
Print "小盒个数是" & p & " " & " 中盒个数是" & q & " " & "大盒个数是" & r
End If
Next r
Next q
Next p
End Sub
3.Private Sub Command1_Click()
For i = 1 To 4
Select Case i
Case 1
Print "*"
Case 2
Print "**"
Case 3
Print "***"
Case 4
Print "****"
End Select
Next i
End Sub
4.Private Sub Command1_Click()
For a = 1 To 99
For b = a + 1 To 100
For c = 1 To 100
If a ^ 2 + b ^ 2 = c ^ 2 Then
Print a, b, c
End If
Next c
Next b
Next a
End Sub