原始碼:http://down.gogobox.com.tw/t2329175/7r2m2
程式碼:
Public Class Form1
Dim key, Target As Long

Private Sub Bu1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bu1.Click
La2.Visible = True '提示計算中
La1.Text = "" '清空結果
System.Windows.Forms.Application.DoEvents() '釋放控制權
Target = Val(TB1.Text)
Dim tmp As Long
Dim Num(20) As Int32, Numx(20) As Long
Dim Rear As Int32 = -1
tmp = Target \ 2
For i As Long = 2 To tmp
If NumCheck(Target) = True And Target > 1 Then
Rear += 1
Num(Rear) = Target
Numx(Rear) += 1
Exit For
End If
If i > 2 And Val(Mid(Str(i), Str(i).Length, 1)) Mod 2 = 0 Then i += 1
If Target Mod i = 0 Then
Rear += 1
Num(Rear) = i
Do While Target Mod i = 0
Target /= i
Numx(Rear) += 1
Loop
End If
Next
La2.Visible = False '結束提示
System.Windows.Forms.Application.DoEvents() '釋放控制權
For i As Integer = 0 To Rear
If Numx(i) <> 1 Then
La1.Text = La1.Text & Str(Num(i)) & " ^" & Str(Numx(i)) & " *"
Else
La1.Text = La1.Text & Str(Num(i)) & " *"
End If
Next
La1.Text = Mid(La1.Text, 1, La1.Text.Length - 1)
End Sub

Public Function NumCheck(ByVal key As Long) As Boolean
NumCheck = True
Dim tmp As Long = key \ 2
For i As Long = 2 To tmp
If key Mod i = 0 Then
NumCheck = False
Exit Function
End If
Next
End Function
End Class


讓地獄深紅的天亮 發表在 痞客邦 PIXNET 留言(0) 人氣()