Microsoft Visual Basic 2005 Ex
20大於A的最小質數等於23
2007-01-06 17:51:32 · 1 個解答 · 發問者 Angel Lin 1 in 電腦與網際網路 ➔ 程式設計
要有程式演練過程
要完成偵錯程式
所以麻煩越詳盡越好
2007-01-06 17:54:13 · update #1
Public Sub Prime2()
Dim i, a, n, done As Integer
Dim buf As String
Do
n = Val(InputBox("請輸入 n (>0) :"))
Loop Until (n > 0)
If (n = 1) Then
Print "大於 1 的最小質數等於 2"
Else
done = 0: a = n
Do
a = a + 1
If (a Mod 2 = 1) Then
For i = 3 To Sqr(a) Step 2
If (a Mod i = 0) Then i = a + 1
Next i
If (i < a + 1) Then done = 1
Else
done = 0
End If
Loop Until (done = 1)
Print "大於 " & n & " 的最小質數等於 " & a
End If
End Sub
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.
2007-01-07 22:01:52 · answer #1 · answered by JJ 7 · 0⤊ 0⤋