April 6, 2008

VB程式-質數

VB程式-質數








輸入一正整數後,



會跑出從1到輸入的數之間的質數。



程式碼如下:









Private Sub Command1_Click()


n = Val(InputBox("輸入任一整數"))

If n >= 2 Then


msg = "1~" & n & "的質數有" & "2" & "ˋ"


End If


i = 1


Do Until i > 1


a = 0


j = 1


Do While j > i


If i Mod j = 0 Then


a = a + 1


j = j + 1


Loop


If a = 2 Then


msg = msg & i & "ˋ"


i = i + 2


Loop


msg = Left(msg, Len(msg) - 1)


MsgBox msg


End Sub

0推薦此文章
Today's Visitors: 0 Total Visitors: 70
Personal Category: VB程式 Topic: creation / design
Previous in This Category: VB程式-空心菱形   Next in This Category: VB程式-質因數
[Trackback URL]

Reply
  • 1樓

    1樓搶頭香

    請問a是什麼意思的存在?

  • at April 11, 2012 12:46 AM comment
Post A Comment









Yes No



Please input the magic number:

( Prevent the annoy garbage messages )
( What if you cannot see the numbers? )
Please input the magic number

誰來收藏
Loading ...
unlog_NVPO 0