Posted By

Scooter on 06/28/08


Tagged

math


Versions (?)

Factors


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/06/factors.html

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Returns an array containing all factors for a given integer.
  10. function factors(x)
  11. dim i
  12. dim arrFactors
  13. arrFactors = Array()
  14.  
  15. for i = 2 to x
  16. if x mod i = 0 then
  17. redim preserve arrFactors(UBound(arrFactors) + 1)
  18. arrFactors(UBound(arrFactors)) = i
  19. end if
  20. next
  21.  
  22. factors = arrFactors
  23. end function
  24. %>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Scooter on September 28, 2008

Fixed a "subscript out of range" bug.

You need to login to post a comment.