問1~100 質數 的VB6.0 的程式碼

2010-03-25 9:42 pm
直接打出來給我

讓我可以直接複製就好

謝摟
更新1:

最好還可以告訴我 位蛇抹是這樣

回答 (4)

2010-03-25 10:22 pm
✔ 最佳答案


質數:只有由1和數字本身所
組成的數,就是質數。


拉一個CommandButton、Text,執行點Command1即可:
求出來的質數會顯示在Text上。


Option Explicit

Private Sub Command1_Click()
Dim i, x, y, z As Integer

Text1.Text = ""

For x = 2 To 100
z = 0
For y = 2 To 100
If x <> y Then
If x Mod y = 0 Then
z = z + 1
Exit For
End If
End If
Next
If z = 0 Then
Text1.Text = Text1.Text & x & " "
End If

Next

End Sub

2010-03-31 10:10 am
其實要算某範圍的質數 003 用的方法會比較快吧。

zerojudge 有許多類似的題目,大家可以去練習看看。

用 001 002 的方法大概都無法在時限內求出解答。

2010-03-31 11:00:51 補充:
我說的是它的想法

它的程式有沒有少指令

我沒注意看

拍謝

2010-04-03 02:45:27 補充:
http://zerojudge.tw/ShowProblem?problemid=d438

這題去練習看看吧。

2010-04-03 02:52:57 補充:
http://zerojudge.tw/BestSolutions?problemid=d438&language=BASIC
2010-03-26 6:10 pm
print "2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97"

搞定收工~~~

2010-03-26 10:14:24 補充:
'宣告變數
Dim I As Integer
Dim Tmp As Integer
Dim XT(100) As Boolean

2010-03-26 10:14:29 補充:
'將所有值設定成true
For I = 0 To 100
XT(I) = True
Next I
'從2開始到100
For I = 2 To 100
'如果是質數
If XT(I) = True Then
'存到text1
Text1.Text = Text1.Text & I & ","
'將後面的倍數都設為false,直到小於100
Tmp = 2
Do Until Tmp * I > 100
XT(Tmp * I) = False
Tmp = Tmp + 1
Loop
End If
參考: 危機百顆查到的, 最慢但是最簡單的原理, 最慢但是最簡單的原理
2010-03-26 1:07 am
Option Explicit
Private Sub Form_Load()
Const n As Integer = 100
Dim flag As Integer
Dim i As Integer, j As Integer
Dim S As String
S = "2"
For i = 3 To n Step 2
flag = 0
For j = 3 To i - 1 Step 2
If i Mod j = 0 Then flag = flag + 1
Next
If flag = 0 Then S = S & " " & i
Next
Text1.SelText = S
End Sub

2010-04-02 20:48:32 補充:
003的方法看起來沒問題
剛剛想來做個測速實驗
卻發現會有範圍才到2000...
答案裡會有2000 1998 1996 1994 ...等等非質數者

2010-04-02 20:50:34 補充:
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,

2010-04-02 20:50:37 補充:
155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,

範圍200的答案


收錄日期: 2021-05-03 13:17:58
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100325000016KK03245

檢視 Wayback Machine 備份