Factors of an integer: Difference between revisions

m
Line 2,924:
clear local mode
local fn IntegerFactors( f as long ) as CFStringRef
long i, s, l(100), c = 0
CFStringRef factorStr = @""
 
for i = 1 to sqr(f)
if ( f mod i == 0 )
l(c) = i
c++
if ( f != i ^ 2 )
l(c) = ( f / i )
c++
end if
end if
next i
 
s = 1
while ( s = 1 )
s = 0
for i = 0 to c-1
if l(i) > l(i+1) and l(i+1) != 0
swap l(i), l(i+1)
s = 1
end if
next i
wend
 
for i = 0 to c - 1
if ( i < c - 1 )
factorStr = fn StringWithFormat( @"%@ %ld, ", factorStr, l(i) )
else
factorStr = fn StringWithFormat( @"%@ %ld", factorStr, l(i) )
end if
next
end fn = factorStr
 
416

edits