Factors of an integer: Difference between revisions

(Factors of an integer in Asymptote)
Line 2,920:
 
=={{header|FutureBasic}}==
<lang futurebasic>window 1, @"Factors of an Integer", (0,0,1000,270)
include "ConsoleWindow"
 
clear local mode
local fn IntegerFactors( f as long ) as Str255CFStringRef
dimlong as long i, s, l(100), c : c = 0
CFStringRef factorStr = @""
dim as Str255 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 l( i) <> c -l(i+1) and l(i+1) != 0
swap l(i), l(i+1)
factorStr = factorStr + str$(l(i)) + ","
s = else1
end if
factorStr = factorStr + str$(l(i))
next i
end if
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 )
 
</lang>
HandleEvents</lang>
 
Output:
416

edits