【正文】
s Integer 39。十位上的數(shù)字 Dim one As Integer 39。個位上的數(shù)字 For i = 100 To 999 hundred = 1 ten = (i Mod 100) \ 10 one = 2 If 3 Then i。 is armstrong number End If Next i End Sub 主題六:錢的拆分 ? 過程 money用于統(tǒng)計工資 salary共需要多少張百元? 50元? 10元? 5元以及 1元的面額。 salary=val(inputbox(“錄入工資數(shù)” )) temp = salary hundred = temp\ 100 temp = temp mod 100 fifty = temp \ 50 temp = temp fifty * 50 ten = temp\ 10 temp = temp mod 10 five = temp \ 5 temp = temp five * 5 one = temp Print hundred, fifty, ten, five, one 主題:最小公倍數(shù)、最大公約數(shù) ? 實(shí)現(xiàn)求任意兩個正整數(shù)的最大公約數(shù) Do m = Val(InputBox(m=)) n = Val(InputBox(n=)) Loop While m = 0 or n = 0 39。先將兩個整數(shù)中的較小數(shù)假設(shè)為最大公約數(shù),再依次往下 39。尋找能同時除盡 m和 n的數(shù)即為最大公約數(shù) div = m If n m Then div = n End If Do until ? div = div 1 Loop m。 和 。 n。 的最大公約數(shù)是: 。 div 主題:最小公倍數(shù)、最大公約數(shù) 輸入 n個整數(shù),求它們的最小公倍數(shù) Private Sub Form_Click() Dim i As Integer, gbs As Long, n As Integer n = InputBox(n=, 數(shù)組元素的個數(shù) n) ReDim a(n) As Integer For i = 1 To n a(i) = InputBox(a( + Str(i) + )=, 輸入數(shù)組元素 ) Next i gbs = a(1) Do For i = 2 To n If gbs Mod a(i) 0 Then gbs = gbs + a(1): Exit For Next i Loop Until i = n + 1 Print gbs End Sub 主題:最小公倍數(shù)、最大公約數(shù) 分析 : 求最大公約數(shù)有許多方法。這里采用 輾轉(zhuǎn)相除法 。 設(shè) m = n * a + R1( 0≤R1n),就是說 m是 n的 a倍還多 R1。 則 m 和 n 的最大公約數(shù)與 n 和 R1 的最大公約數(shù) 相同 。 若 R1 等于 0 ,則 n 就是 m 和 n 的 最大公約數(shù) 。 若 R1 不等于 0,則對 n和 R1重復(fù)上述過程,直到求出 R1等于 0為止。 步驟: ?( 1) 對于已知兩數(shù) m、 n, 使得 mn; ?( 2) m除以 n得余數(shù) r; ?( 3) 若 r=0, 則 n為最大公約數(shù) , 算法結(jié)束;否則執(zhí)行步驟 ( 4) ; ?( 4) m←n , n←r , 再重復(fù)執(zhí)行步驟 ( 2) 輾轉(zhuǎn)相除法求最大公約數(shù) ?Private Sub Form_Click() m = Val(InputBox(錄入一個數(shù) )) n = Val(InputBox(錄入一個數(shù) )) If m n Then t = m: m = n: n = t r = m Mod n While r 0 m = n : n = r: r = m Mod n Wend Print n End Sub 主題:迭代法 ?求 fibonacci數(shù)列前 30項(xiàng)的值 F1=1:f2=1 Fn=fn1+fn2 Private Sub Form_Click() Dim f1 As Long, f2 As Long, f3 As Long, i As Integer f1 = 1 : f2 = 1 Print f1。 f2。 For i = 3 To 30 39。用循環(huán)顯示后 28個數(shù) f3 = f1 + f2 Print f3。 f1 = f2 f2 = f3 Next i End Sub Public Sub Fabonia() Dim last_one As Long Dim last_two As Long Dim this_one As Long Dim i As Integer last_one = 1 39。數(shù)列的第二個數(shù) last_two = 2 39。數(shù)列的第三個數(shù) i = 4 39。從數(shù)列的第四個數(shù)求起 Do this_one = last_one + last_two last_one = 1 last_two = 2 If i = 17 Then No:17=。 this_one End If 3 Loop While this_one = 100000000 No:。4。 is 1E+8 End Sub 該過程是對以下數(shù)列進(jìn)行運(yùn)算:有一個數(shù)列,它的前三個數(shù)是 0, 1, 2, 從第四個數(shù)起,每個數(shù)都是它前面的兩個數(shù)之和 ,求出該數(shù)列的第 17個數(shù)是多少 ? 求出該數(shù)列的第幾個數(shù)起每個數(shù)都超過 1E+8