Jump to content

Factors of an integer: Difference between revisions

Added FutureBasic example
m (→‎{{header|PL/I}}: removed the red tag.)
(Added FutureBasic example)
Line 1,232:
The set of factors of 639 is {9, 639, 71, 213, 1, 3}
The set of factors of 760 is {8, 19, 4, 40, 152, 5, 10, 76, 1, 95, 190, 760, 20, 2, 38, 380}
</pre>
 
 
=={{header|FutureBasic}}==
<lang futurebasic>
include "ConsoleWindow"
 
clear local mode
local fn IntegerFactors( f as long ) as Str255
dim as long i, s, l(100), c : c = 0
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 ( i < c -1 )
factorStr = factorStr + str$(l(i)) + ","
else
factorStr = factorStr + str$(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>
 
Output:
<pre>
Factors of 25 are: 1, 5, 25
Factors of 45 are: 1, 3, 5, 9, 15, 45
Factors of 103 are: 1, 103
Factors of 760 are: 1, 2, 4, 5, 8, 10, 19, 20, 38, 40, 76, 95, 152, 190, 380, 760
Factors of 12345 are: 1, 3, 5, 15, 823, 2469, 4115, 12345
Factors of 32766 are: 1, 2, 3, 6, 43, 86, 127, 129, 254, 258, 381, 762, 5461, 10922, 16383, 32766
Factors of 32767 are: 1, 7, 31, 151, 217, 1057, 4681, 32767
Factors of 57097 are: 1, 57097
Factors of 12345678 are: 1, 2, 3, 6, 9, 18, 47, 94, 141, 282, 423, 846, 14593, 29186, 43779, 87558, 131337, 262674, 685871, 1371742, 2057613, 4115226, 6172839, 12345678
Factors of 32434243 are: 1, 307, 105649, 32434243
</pre>
 
729

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.