【電腦軟體設計】電腦軟體設計-丙級-術科測驗1站-第3題 - 東哥的G3之戀 - udn部落格
東哥的G3之戀
作家:東哥(沉浸在幸福裡!)
文章分類
    Top
    【電腦軟體設計】電腦軟體設計-丙級-術科測驗1站-第3題
    2010/02/20 09:37:04
    瀏覽:2192
    迴響:0
    推薦:2
    引用0


    第3題解題程式


    FOR迴圈版
    Private Sub cmd_no3_Click()
    '**************************
    '*119-940303 Program Start*
    '**************************
    Open "A:\940303.SM" For Input As #1
    Input #1, n
    Close #1
    For a = 2 To n - 1                    '用2到N-1去除N
        If (n Mod a) = 0 Then             '如果N可以被2到N-1整除,N就不是質數
        S = n & " is not a prime number"  '顯示N不是質數
        Exit For
        End If
        S = n & " is a prime number"      '如果2到N-1都不能整除N,N就是質數
    Next

    Txt_no3.Text = "第三題結果:" & S

    End Sub

    DO WHILE 迴圈版
    Private Sub cmd_no3_Click()
    '**************************
    '*119-940303 Program Start*
    '**************************
    Open "A:\940303.SM" For Input As #1
    Input #1, n
    Close #1
    a = 2

    Do While a < n
    If (n Mod a) = 0 Then
    S = n & " is not a prime number"
    Exit Do
    End If
    a = a + 1
    S = n & " is a prime number"
    Loop

    Txt_no3.Text = "第三題結果:" & S

    End Sub

    DO WHILE後測試版
    Private Sub Cmd_no3_Click()
    '**************************
    '*119-940303 Program Start*
    '**************************
    Open "A:\940303.SM" For Input As #1
    Input #1, n
    Close #1
    a = 2
    Do
    If (n Mod a) = 0 Then
    S = n & " is not a prime number"
    Exit Do
    End If
    a = a + 1
    S = n & " is a prime number"
    Loop While a < n

    txt_no3.Text = "第三題結果:" & S


    End Sub

    執行畫面



    回應
    發表迴響

    會員登入