vb编程题 从键盘上输入一个整数,判断其能否被5整除

2024-11-10 22:25:58
推荐回答(3个)
回答1:

Dim inNum As String
inNum = InputBox("输入一个整数,如果不是整数自动转换为整数")
If InStr(1, inNum, ".") <> 0 Then inNum = Left(inNum, InStr(1, inNum, ".") - 1)
If Right(inNum, 1) = 0 Then
MsgBox "数值" & inNum & "能够被5整除"
ElseIf Right(inNum, 1) = 5 Then
MsgBox "数值" & inNum & "能够被5整除"
Else
MsgBox "数值" & inNum & "不能被5整除"
End If

'速度有点慢了,但是支持的长度绝对比上面的好,上面的最多9位数的,然后就溢了……

回答2:

dim a as integer
a=inputbox( "请输入一个数")
if a mod 5 =0 then
msgbox "能被5整除"
else
msgbox "不能被5整除"
endif

回答3:

dim l as long
l = 键盘输入的数
if abs(l) <5 then msgbox "不能整除"
if abs(l) mod 5 then
msgbox "不能整除"
else
msgbox "可以整除"
endif