vb随机生成10个[-50,50]之间整数,分别统计其中正数之和和负数之和
vb随机生成10个[-50,50]之间整数,分别统计其中正数之和和负数之和
如题,这是第一题,第二题是
实现程序功能是在文本框中输入一个整数n,单击命令按钮,则找出的数字按以下规律排列:每个数是前面2个数之和,最后1个数是满足上述规律的最大的小于n的数,第一项和第二项的值为1.如输入10,则显示数字有:2、3、5、8.
这2个题
'第一题:
Private Sub Command1_Click()
Dim va As Long, vb As Long
Dim i As Long, vt As Long
Me.Cls
va = 0: vb = 0
Me.Print "10个整数是:"
For i = 1 To 10
vt = Rnd() * 100 - 50
Me.Print vt;
If (vt > 0) Then
va = va + vt
Else
vb = vb + vt
End If
Next
Me.Print vbLf & "正数之和: " & va
Me.Print "负数之和: " & vb
End Sub
'第二题:
Private Sub Command2_Click()
Dim va As Long, vb As Long
Dim i As Long, vt As Long
i = Val(Text1)
Me.Cls
va = 1: vb = 1
Do
vt = vb + va
If (vt > i) Then Exit Do
Me.Print vt;
va = vb: vb = vt
Loop
End Sub