vb编程解答
帮我编几个VB程序,题目如下:
1.*
**
***
****
这个类型的正金字塔和倒金字塔
2. 1-2+3-4+5-6+……+99-100的值
3.随机生成20个大于100的正整数值
随机生成20个两位数数组,输出该数组中的最大值
4.把1000年到5000年中的所有的闰年放入到list1里,计算闰年和放入到text1里
1000以内的所以质数放入list1,质数和放入text1里
5.设计出程序,两位数加减法
请帮忙回答,谢谢各位了!
程序编出后还会追加积分!
补充:第四题的质数那个答案好像不对
答案:'第一题答案
Private Sub Command1_Click()
Print "正的如下:"
For i = 1 To 4
Print String(i, "*")
Next i
Print "倒的如下"
For i = 4 To 1 Step -1
Print String(i, "*")
Next i
End Sub
'第二题答案
Private Sub Command1_Click()
For i = 1 To 100
s = s + (-1) ^ (i + 1) * i
Next i
Print s
End Sub
'第三题答案
Private Sub Command1_Click()
Dim a(1 To 20) As Integer, b(1 To 20) As Integer
Randomize Timer
Print "随机产生20个大于100的正整数是:"
For i = 1 To 20
a(i) = Int(Rnd * 899 + 101)
b(i) = Int(Rnd * 90 + 10)
Print a(i); " ";
If i Mod 10 = 0 Then Print
Next i
Print "随机产生的20个两位数是:"
For i = 1 To 20
Print b(i); " ";
If i Mod 10 = 0 Then Print
Next i
Max = 0
For i = 1 To 20
If b(i) > Max Then Max = b(i)
Next i
Print "最大值是:" & Max
End Sub
'第四题答案 (闰年)
Private Sub Command1_Click()
For i = 1000 To 5000
If (i Mod 4 = 0 And i Mod 100 <> 0) Or i Mod 400 = 0 Then List1.AddItem i
Next i
End Sub
'第四题答案(1000以内质数)
Private Sub Command1_Click()
For i = 2 To 1000
If Prime(i) Then
List1.AddItem i
s = s + i
End If
Next i
Text1.Text = s
End Sub
Function Prime(z) As Boolean
For i = 2 To Sqr(z)
If z Mod 2 = 0 Then
Prime = False
Exit Function
End If
Next i
Prime = True
End Function
上一个:求VB编程
下一个:vb编程题