English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問各位高手要如何用VB寫出三數的最大公因數
求兩數的最大公因數是這樣的:
A = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text4.Text)
R = A Mod b
Do While R <> 0
A = b
c = b
R = A Mod b
Loop
Text3.Text = b
那求三數呢? 拜託各個高手 感激不盡

2006-09-09 13:20:14 · 2 個解答 · 發問者 佩穎 1 in 電腦與網際網路 程式設計

2 個解答

Private Sub Command1_Click()    Dim A, I As Integer, S As Long        A = Array(Val(Text1), Val(Text2), Val(Text3))    For I = 0 To UBound(A)        S = GCD(S, A(I))    Next    Print Join(A, ","); " 之最大公因數為"; SEnd SubFunction GCD(ByVal S1 As Long, ByVal S2 As Long) As Long    Dim T As Long        Do While S1 Mod S2      T = S1 Mod S2: S1 = S2: S2 = T    Loop    GCD = S2End Function

2006-09-09 13:54:30 · answer #1 · answered by W.J.S. 7 · 0 0

10-2*5=0,10/2-5=0,10/2/5=1,10-2-5=3,
10+2-5=7,10/2+5=10,10-2+5=13,10*2-5=15,
10+2+5=17,10+2*5=20,10*2+5=25,
10*2*5=100,10/2*5=25,10*2/5=4.

2006-09-09 13:26:06 · answer #2 · answered by 阿杰 1 · 0 0

fedest.com, questions and answers