50 lines
1.3 KiB
Text
50 lines
1.3 KiB
Text
window 1, @"Factors of an Integer", (0,0,1000,270)
|
|
|
|
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
|
|
|
|
print @"Factors of 25 are:"; fn IntegerFactors( 25 )
|
|
print @"Factors of 45 are:"; fn IntegerFactors( 45 )
|
|
print @"Factors of 103 are:"; fn IntegerFactors( 103 )
|
|
print @"Factors of 760 are:"; fn IntegerFactors( 760 )
|
|
print @"Factors of 12345 are:"; fn IntegerFactors( 12345 )
|
|
print @"Factors of 32766 are:"; fn IntegerFactors( 32766 )
|
|
print @"Factors of 32767 are:"; fn IntegerFactors( 32767 )
|
|
print @"Factors of 57097 are:"; fn IntegerFactors( 57097 )
|
|
print @"Factors of 12345678 are:"; fn IntegerFactors( 12345678 )
|
|
print @"Factors of 32434243 are:"; fn IntegerFactors( 32434243 )
|
|
|
|
HandleEvents
|