编制判断奇偶数的Function函数:输入一个整数,判断其奇偶性。

来源:百度知道 编辑:UC知道 时间:2024/05/10 04:35:25

Function GetOE(Num As Long) As String
GetOE = IIf(Num Mod 2, "奇数", "偶数")
End Function

Private Sub Command1_Click()
MsgBox GetOE(InputBox("请输入一个整数:", , 8))
End Sub

'添加窗体Form1,按钮Command1,然后添加如下代码:
Private Sub Command1_Click()
    Dim a As Integer
    a = Int(InputBox("输入一个整数:"))
    MsgBox IIf(isOddNum(a), "奇数", "偶数")
End Sub

Private Function isOddNum(int1 As Integer) As Boolean
    isOddNum = IIf(int1 Mod 2 = 0, False, True)
End Function

Private Sub ChkNum(s)
if s mod 2 = 0 then '除以2,余数为0则为偶数,否则为奇数
msgbox "偶数"
else
msgbox "奇数"
end if
End Sub