VB题目!感谢

来源:百度知道 编辑:UC知道 时间:2024/06/10 06:05:25
“哥德巴赫猜想”指出,每个大于6的偶数,都可以表示为两个素数的和。试用程序将6-100内的所有偶数都表示为两个素数的和。
我没学过VB,别人让帮忙的!

dim a(100) as integer
dim i as integer,j as integer,k as integer

private sub form_load()
for i=6 to 100 step 2
for j=2 to i
if su(j) then
if su(i-j) then
print i;"=";j;"+";i-j
end if
end if
next
next
end sub

sub su(shu as integer) as boolean '判断shu是否是质数
dim x as integer,y as integer
if shu=2 then
su=true
else
for x=2 to shu-1
if shu mod x =0 then
su=false
exit for
else
su=true
endif
next
end sub

都帮你做了好几题了,没分真的不想再做了~

'算素数的函数
Private Sub Ss(ByRef X() As Long, ByRef Xcount As Long, ByVal Sform As Long, ByVal Sto As Long)
Dim i As Long
Dim j As Long
Xcount = 0
For i = Sform To Sto
j = 2
Do Until (i Mod j) = 0 Or j > i / 2
j = j + 1
Loop
If j > i / 2 Then
Xcount = Xcount + 1
ReDim Preserve X(1 To Xcount) As Long
X(Xcount) =