2009年4月24日 星期五

因數分解 -- 多個數

image

'因數分解 -- 多個數
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim rStr = ""

        Dim n() = {1, 12, 24, 369}

        For j As Integer = 0 To UBound(n)
            Dim nb = n(j)
            Dim str1 = "1"
            Dim i = 2
            While n(j) <> 1
                If n(j) Mod i = 0 Then
                    str1 = str1 & "x" & i
                    n(j) = n(j) / i
                Else
                    i = i + 1
                End If
            End While
            rStr = rStr & nb & "=" & str1 & vbNewLine
        Next
        MsgBox(rStr)
    End Sub
End Class

沒有留言:

張貼留言