I've written a function to check the divisibility of a number.
For me, this is the best solution:
Public Function CheckDiv(ByVal N As Integer) As List(Of Integer)
Dim RetList As New List(Of Integer)
For I As Integer = 2 To 10
If N Mod I = 0 Then
RetList.Add(I)
End If
Next
Return RetList
End Function
Using a
for
, we check if a number is divisible by 2,3,...,10. The
mod
operator returns the rest of a division. If it's 0, N is divisible by I.
The solution with the
case
is ugly; I advice you to use the first one! However, here it is:
Public Function CheckDiv(ByVal N As Integer) As List(Of Integer)
Dim Ret As New List(Of Integer)
For I As Integer = 2 To 10
If N Mod I = 0 Then
Select Case I
Case 2
Ret.Add(2)
Case 3
Ret.Add(3)
Case 4
Ret.Add(4)
Case 5
Ret.Add(5)
Case 6
Ret.Add(6)
Case 7
Ret.Add(7)
Case 8
Ret.Add(8)
Case 9
Ret.Add(9)
Case 10
Ret.Add(10)
End Select
End If
Next
Return Ret
End Function
Hope this helped!