2009年4月9日 星期四

求質因數

image

'求質因數
Public Class Form1
    Dim i, j
    Dim str1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim n = 110
        For i = 1 To n
            '判斷是否為因數
            If n Mod i = 0 Then
                '第11-17列 判斷是否為質數
                Dim c = 0
                For j = 1 To i
                    If i Mod j = 0 Then c = c + 1
                Next
                If c = 2 Then
                    str1 = str1 & i & "  "
                End If
            End If
        Next
        MsgBox(str1)
    End Sub
End Class

沒有留言:

張貼留言