English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

如何用form的程式判斷數字是否為質數???
請附上完整的程式及註解!!!

2006-04-03 14:01:11 · 5 個解答 · 發問者 泰爺 1 in 電腦與網際網路 程式設計

5 個解答

Private Sub Form_Activate()

Dim f As Boolean
n = Val(InputBox(""))
For q = 2 To n
f = True
For w = 2 To n \ 2
If n Mod w = 0 Then f = False: Exit For
Next
Next
If f Then
MsgBox (n & "是質數")
Else
MsgBox (n & "不是質數")
End If

End Sub

如果還有什麼問題可以再問吧~~

2006-04-04 21:44:18 補充:
to 泰爺
如果有看不懂得可以問我~~~
我是那個"問號"
>"

2006-04-03 20:16:35 · answer #1 · answered by 小均 2 · 0 0

請問Dim f As Boolean還有 f = False: Exit For是什麼意思?

2006-04-05 18:35:38 · answer #2 · answered by 泰爺 1 · 0 0

http://www.tvbs2100.com/ezs/vb/vb-index.htm
我的程式 歡迎參考看看

2006-04-04 11:44:53 · answer #3 · answered by 小毛 5 · 0 0

'值數不就是與比他小比二大的東西都互質嗎?
用法:trackprime(數字)


function trackprime(totrack as integer)
dim ans as boolean
ans = true
for i = 2 to totrack
'從2開始比較
if totrack mod i = 0 then
'假如這i是totrack的因數,就傳回否
ans = false
'假如都沒有他的因數,這答案就不用改了,一定是True
exit for
end if
next i

return ans
end function

2006-04-03 19:55:35 補充:
我想是用form_load吧

2006-04-03 15:26:39 · answer #4 · answered by Anonymous · 0 0

什麼市form的程式?

2006-04-03 14:41:14 · answer #5 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers