【正文】
teger, n As Integer n = InputBox(請輸入數(shù)列項數(shù)) ReDim a(n) For i = 1 To n a(i) = Int(Rnd * 10 * n + 1) Print a(i)。 NextEnd SubPrivate Sub Form_Load()End Sub15.編寫程序,在窗體上輸出3~100之間的所有素數(shù)。Public a As IntegerPrivate Function fact(n) As Long If n = 1 Then fact = 1 ElseIf n = 2 Then fact = 1 Else: fact = fact(n 2) + fact(n 1) End IfEnd FunctionPrivate Sub Command1_Click()n = InputBox(請輸入n)Print fact(n)End SubPrivate Function s(n) As Longs1 = 1: s2 = 1For i = 1 To n 2 s = s1 + s2: t = s2: s2 = s: s1 = tNextEnd FunctionPrivate Sub Command2_Click()n = InputBox(請輸入n)Print s(n)End Sub17. 編寫2個函數(shù),分別采用遞歸法和遞推法求斐波納契數(shù)列的第n個月的兔子數(shù),n使用inputbox輸入,調(diào)用函數(shù)的結(jié)果在窗體上顯示。Print bc = a 100 * bb = Fix(c / 50) Print 50元:。 Print b c = c * bb = Fix(c / ) Print :。 a amp。 a * b。Next iPrintEnd Sub6. 求平方根Option ExplicitPrivate Sub Command1_Click()Dim a As Double, b As Double, c As Double, i As Doublea = 0c = b = cDo While Abs(((a + b) / 2) ^ 2 c) 10 ^ (5)i = (a + b) / 2 If i ^ 2 c 0 Then b = i ElseIf i ^ 2 c = 0 Then Exit Do Else a = i End IfLoopMsgBox (i)End Sub7. 閏年Option ExplicitPrivate Sub 計算_Click()Dim i As Integeri = InputBox(請輸入一個年份)If i Mod 4 = 0 And i Mod 400 = 0 Then If i Mod 100 0 Then MsgBox NOT Else MsgBox YES End IfElse MsgBox NOTEnd IfEnd Sub8. 三角Option ExplicitPrivate Sub Command1_Click()Dim a As SingleDim b As SingleDim c As SingleDim p As SingleDim s As Singlea = b = c = p = (a + b + c) / 2s = Sqr((p a) * p + (p b) * p + (p c) * p) = sEnd Sub9. 求素數(shù)Private Sub Command1_Click()Dim n As Double, i As Doublen = InputBox(請輸入一個數(shù):)For i = 2 To n 1 If n Mod i = 0 Then MsgBox NOT Exit For End IfNext iIf i = n Then MsgBox YESEnd IfEnd SubPrivate Sub Command2_Click()Dim a As Boolean, n As Double, i As Doublea = Falsen = InputBox(請輸入一個數(shù):)For i = 2 To n 1 If n Mod i = 0 Then a = True Exit For End IfNext iIf a = True Then MsgBox NOTElse MsgBox YESEnd IfEnd SubPrivate Sub Command3_Click()Dim n As Double, i As Doublen = InputBox(請輸入一個數(shù):)i = 2Do While i n If n Mod i = 0 Then MsgBox NOT Exit Do End Ifi = i + 1LoopIf i = n Then MsgBox YESEnd IfEnd SubPrivate Sub Command4_Click()Dim n As Double, i As Double, sushu As Booleann = InputBox(請輸入一個數(shù):)i = 2sushu = TrueDo While i n And sushu = True If n Mod i = 0 Then sushu = False End Ifi = i + 1LoopIf sushu = True Then MsgBox YESElse MsgBox NOTEnd IfEnd Sub 19 / 19。Next iPrintEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, t As IntegerFor i = 1 To 9 For j = 1 + i To 10 If a(i) a(j) Then t = a(j) a(j) = a(i) a(i) = t End If Next jNext iFor i = 1 To 10 Print a(i)。 b。 b)End IfEnd SubPri