M5P01 判斷 S 是11的倍數、15的倍數、33的倍數
變位1 M5P01-1 是否15倍數 , 可以被5整除也可以被3整除
Function M5P01(ByVal s As String) As String
Dim c As Char = Strings.Right(s, 1)
If c<>"0" and
c<>="5" then Return "N" '最後1位非0非5
' 所有位數的總和是3的倍數?
M5P01 = "Y"
Dim sum As Integer = 0
For i = 1 To s.Length
sum += Val(Mid(s, i, 1))
Next i
If sum Mod 3 <> 0 Then Return
"N"
End Function
變位2 M5P01_2 是否33倍數 , 可以被11整除也可以被3整除
Function M5P01_2(ByVal s As String) As
String
M5P01_2 = "Y"
Dim odd As Integer = 0, even As Integer
= 0
For i = 1 To s.Length
If i Mod 2 = 0 Then
even += Val(Mid(s, i, 1))
Else
odd += Val(Mid(s, i, 1))
End If
Next
If Math.Abs(odd - even) Mod 11 <>
0 Then Return "N" '非11倍
If (odd + even)
Mod 3 <> 0 Then Return "N" '非3倍
End Function
0 意見:
張貼留言