2012年11月20日 星期二

vb選手第二次測試 1st

請找出在integer範圍內最大的兩個質數

3 則留言:

  1. Dim notwant As Boolean
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #1
    For i = 32767 To 1 Step -1
    For ii = 2 To i - 1
    If i Mod ii = 0 Then notwant = True: Exit For
    Next
    If notwant = False Then Print #1, i: mycount = mycount + 1
    notwant = False
    If mycount = 2 Then Exit For
    Next

    Close #1
    End
    End Sub

    回覆刪除
  2. 作者已經移除這則留言。

    回覆刪除
  3. Dim tof As Boolean
    Private Sub Form_Load()
    Me.Hide
    'Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    s = 0
    For i = 32767 To 1 Step -1
    tof = False
    For j = 2 To (i - 1) / 2
    If i Mod j = 0 Then tof = True: Exit For
    Next j
    If tof = False Then Print #2, i: s = s + 1
    If s = 2 Then End
    Next i
    Close #2
    'Close #1
    End
    End Sub

    回覆刪除