- 威望
- 0
- 貢獻
- 156
- 參與
- 0
- GJ
- 529
- 註冊時間
- 2005-6-27
|
6#
發表於 2009-12-27 15:56
| 只看該作者
與友人討論後寫出來的結果
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sum, input As Long
input = Val(TextBox1.Text)
If input Mod 2 = 1 And input >= 1 And input <= 19 Then
For index As Long = 1 To input Step 2
sum = sum + Factorial(index)
Next
MsgBox(sum)
Else
MsgBox("Please enter any odd number that is larger than 1 and between 1 & 19 ")
End If
End Sub
Private Function Factorial(ByVal number As Long) As Long
If number <= 1 Then
Return (1)
Else
Return number * Factorial(number - 1)
End If
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Focus()
End Sub
End Class
請大家看一下有哪些地方需要改進
[ 本文最後由 Iverson 於 2009-12-27 16:38 編輯 ] |
|