Divisors

This code show how to find the divisors of the given number.


Private Sub Divisors()
Dim intNum, intDiv As Integer
Dim strDiv As String = ""

'Consider variable intNum as number
'whose divisors are to be searched.
intNum = 100
'Every number is divisible by 1.
'So start dividing from 1.
intDiv = 1
While (intDiv < intNum / 2)
'If the remainder is 0 then
'the current value of intDiv
'is the divisor of the number intNum.
If intNum Mod intDiv = 0 Then
'Save all the divisors in the variable strDiv.
If strDiv.Length = 0 Then
strDiv = intDiv
Else
strDiv = strDiv & "," & intDiv
End If
End If
intDiv = intDiv + 1
End While
MessageBox.Show(strDiv)
End Sub


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: