Factors of a number

Factors of a number



This code shows how to find the factors of a number.

Private Sub Factors()
Dim intNum As Integer = 100
Dim intFact As Integer = 2
Dim strOutput As String = ""

'Divide the number till it decrements to 1.
While intNum <> 1
'The number intFact is factor of number
'intNum if the remainder is 0.Save all
'such numbers in variable strOutput.
While (intNum Mod intFact = 0)
intNum = intNum / intFact
If strOutput.Length = 0 Then
strOutput = intFact
Else
strOutput = strOutput & "," & intFact
End If
End While
intFact = intFact + 1
End While
MessageBox.Show(strOutput)
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: