就是例如我打84 那他會顯示84=2*2*3*7
這樣的形式的程式碼
先謝謝你們幫我解答
感激不盡
2006-05-07 07:31:43 · 3 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
'放一個Text1、Command1Option ExplicitPrivate Sub Command1_Click() If IsNumeric(Text1) Then Print Factorize(Text1)End SubPublic Function Factorize(ByVal SurNum As Long) As String Dim Ar(), Num As Long, i%, j%, a%, result$, chk As Boolean Num = SurNum For i = 2 To 900 chk = True For j = 2 To Sqr(i) If (i Mod j = 0) Then chk = False Next j If chk Then a = a + 1 ReDim Preserve Ar(a) Ar(a) = i End If Next i Do For i = UBound(Ar) To 1 Step -1 If (Num / Ar(i)) = Int(Num / Ar(i)) Then Num = Num / Ar(i) result = "*" & Ar(i) & result Exit For End If Next Loop Until Num = 1 Factorize = SurNum & " = " & Mid(result, 2)End Function
2006-05-07 09:37:50 · answer #1 · answered by ? 6 · 0⤊ 0⤋
Private Sub Command1_Click()Dim N&, S$, I&, P&Do S = InputBox("請輸入一個正整數", , 84) If S = "" Then Exit Sub N = Int(Val(S))Loop Until N > 0Print N; "=";Do P = 0 '先找出最小質因數 For I = 2 To Sqr(N) If N Mod I = 0 Then P = I: Exit For Next I If P Then '若有質因數就輸出質因數 Print P; "*"; N = N / P Else '若無質因數就結束 Print N Exit Do End IfLoopEnd Sub
2006-05-08 10:44:52 · answer #2 · answered by W.J.S. 7 · 0⤊ 0⤋
用短除法阿! 請參考http://tw.knowledge.yahoo.com/question/?qid=1306020611079
http://tw.knowledge.yahoo.com/question/?qid=1105070211742
http://tw.knowledge.yahoo.com/question/?qid=1405111410050
因為我也不知該如何說 反正就是用短除法
2006-05-07 07:49:16 · answer #3 · answered by Anonymous · 0⤊ 0⤋