| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 761 人关注过本帖
标题:新手求一白痴程序
只看楼主 加入收藏
珞珞
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-28
收藏
 问题点数:0 回复次数:2 
新手求一白痴程序
帮帮忙啊~谢谢!!


该程序功能是当单击“开始”按钮时,求100到500间的质数并添加在列表框中。当单击“清除”时,清除列表框中的全部内容。




谢谢各位拉
搜索更多相关主题的帖子: 单击 质数 列表 
2007-06-28 16:38
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
收藏
得分:0 

Option Explicit

Sub Prime(n As Long)
Dim a() As Byte, b() As String
Dim i As Long, j As Long, l As Long, p As Long, q As Long
ReDim a(n + 6)
j = 1
l = Sqr(n)
Do
DoEvents
j = j + 4
If a(j) = 0 Then
i = j * j
p = j * 2
q = j * 4
Do While i < n
a(i) = 1
i = i + p
If i > n Then Exit Do
a(i) = 1
i = i + q
Loop
End If
j = j + 2
If a(j) = 0 Then
i = j * j
p = j * 2
q = j * 4
Do While i < n
a(i) = 1
i = i + q
If i > n Then Exit Do
a(i) = 1
i = i + p
Loop
End If
Loop Until j >= l
ReDim b(n \ 3 + 2)
b(0) = "2"
b(1) = "3"
j = 1
i = 1
Do
DoEvents
j = j + 4
If a(j) = 0 Then
i = i + 1
b(i) = j
End If
j = j + 2
If a(j) = 0 Then
i = i + 1
b(i) = j
End If
Loop Until j >= n
ReDim Preserve b(i)
For i = LBound(b) To UBound(b)
If b(i) > 100 And b(i) < 500 Then
List1.AddItem b(i)
End If
Next
End Sub

Private Sub Command1_Click()
Prime 500
End Sub

Private Sub Command2_Click()
List1.Clear
End Sub


2007-06-28 17:18
珞珞
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-6-28
收藏
得分:0 
回复:(心中有剑)Option ExplicitSub Prime(n As ...
谢谢!!
2007-06-29 15:49
快速回复:新手求一白痴程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015608 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved