vb编程!!请高手帮帮忙~~

2024-11-15 07:15:36
推荐回答(1个)
回答1:

1-------
Dim a() As Long
Dim N&
Dim pstr As String

Private Sub Prime(num&)
Dim i&, j&
If num < a(0) Then Exit Sub
For j = a(0) To num Step 2
For i = 2 To N
If j Mod a(i) = 0 Then Exit For
If j < a(i) * a(i) Then
N = N + 1
ReDim Preserve a(N)
a(N) = j
pstr = pstr & "," & a(N)
Exit For
End If
Next i
Next j
a(0) = (num \ 2) * 2 + 1
End Sub

Private Sub Form_Click()
Dim jian&, jia&, k&, i&
k = InputBox("输入不小于6的偶数", , 6)
If Not IsNumeric(k) Then Exit Sub
If k <> Int(k) Then Exit Sub
If k Mod 2 Then Exit Sub
Call Prime(k) '计算较大数字是开始会比较慢,越大越慢
jia = k \ 2
Do
For i = 1 To N
If a(i) > jia Then
If InStr(pstr, k - a(i - 1)) Then
i = i - 1
Exit Do
End If
Else
jian = k - a(i - 1)
End If
Next i
For i = N To 1 Step -1
If a(i) < jian Then
If InStr(pstr, k - a(i + 1)) Then
i = i + 1
Exit Do
End If
Else
jian = k - a(i + 1)
End If
Next i
Loop
Form1.Print a(i) & "+" & (k - a(i))
End Sub

Private Sub Form_Load()
N = 2
ReDim a(N)
a(1) = 2
a(2) = 3
a(0) = 3
pstr = "2,3"
End Sub
2-----------
private sub m(n%)
if n=0 then exit sub
dim i%,j
j=a(10)
for i=1 to 9
a(i+1)=a(i)
next i
a(1)=j
call m(n-1)
end sub
3------------
dim a(99)%,b(9)%,i%
for i=0 to 99
a(i)=int(rnd*100)
b(a(i) mod 10)=b(a(i) mod 10)+1
next i
for i=0 to 9
print "个位上为";i;"的数有";b(i);"个"
next i
4------------
dim a(10 to 100)%,i%,j%
i=50
do while i>0
j=int(rnd*91)+10
if a(j)=0 then
a(j)=1
i=i-1
end if
loop
for i =10 to 100
if a(i)=1 then print a(i);" ";
if i mod 10=0 then print
next i