Factors of an integer: Difference between revisions
Content added Content deleted
Line 2,924: | Line 2,924: | ||
clear local mode |
clear local mode |
||
local fn IntegerFactors( f as long ) as CFStringRef |
local fn IntegerFactors( f as long ) as CFStringRef |
||
long i, s, l(100), c = 0 |
long i, s, l(100), c = 0 |
||
CFStringRef factorStr = @"" |
CFStringRef factorStr = @"" |
||
for i = 1 to sqr(f) |
for i = 1 to sqr(f) |
||
if ( f mod i == 0 ) |
if ( f mod i == 0 ) |
||
l(c) = i |
l(c) = i |
||
c++ |
c++ |
||
if ( f != i ^ 2 ) |
if ( f != i ^ 2 ) |
||
l(c) = ( f / i ) |
l(c) = ( f / i ) |
||
c++ |
c++ |
||
end if |
end if |
||
end if |
end if |
||
next i |
next i |
||
s = 1 |
s = 1 |
||
while ( s = 1 ) |
while ( s = 1 ) |
||
s = 0 |
s = 0 |
||
for i = 0 to c-1 |
for i = 0 to c-1 |
||
if l(i) > l(i+1) and l(i+1) != 0 |
if l(i) > l(i+1) and l(i+1) != 0 |
||
swap l(i), l(i+1) |
swap l(i), l(i+1) |
||
s = 1 |
s = 1 |
||
end if |
end if |
||
next i |
next i |
||
wend |
wend |
||
for i = 0 to c - 1 |
for i = 0 to c - 1 |
||
if ( i < c - 1 ) |
if ( i < c - 1 ) |
||
factorStr = fn StringWithFormat( @"%@ %ld, ", factorStr, l(i) ) |
factorStr = fn StringWithFormat( @"%@ %ld, ", factorStr, l(i) ) |
||
else |
else |
||
factorStr = fn StringWithFormat( @"%@ %ld", factorStr, l(i) ) |
factorStr = fn StringWithFormat( @"%@ %ld", factorStr, l(i) ) |
||
end if |
end if |
||
next |
next |
||
end fn = factorStr |
end fn = factorStr |
||