VB.NET实例:求一个因式分解的程序
作者:转载自:xin3721视频教程网整理更新时间:2010/11/13

输入一个数 然后显示他的因式分解
例如:15=1*3*5
         12=1*2*2*3

答:

Module Module1

    Sub Main()
        Dim input As Integer '定义输入的数
        Dim output As Integer '将Input 传到output
        Dim a(100) As Integer '定义数组
        Dim n As Integer = 0 '判断数组数的个数
        Dim i As Int32
        Console.Write("请输入要分解的数:")
        input = Int32.Parse(Console.ReadLine())
        output = input '将Input 传到output
        For i = 2 To input
            If input Mod i = 0 Then
                a(n) = i
                n = n + 1
                input = input / i
                i = 1
            End If
        Next


        Console.Write("{0}=1", output)
        For n = 0 To n - 1
            Console.Write("*{0}", a(n))
        Next
        Console.ReadLine()
    End Sub


End Module