Factors of an integer: Difference between revisions

m (→‎optimized version: added a bit of clarification to a REXX section header comment. -- ~~~~)
Line 177:
</pre>
 
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f FACTORS_OF_AN_INTEGER.AWK
BEGIN {
print("enter a number or C/R to exit")
}
{ if ($0 == "") { exit(0) }
if ($0 !~ /^[0-9]+$/) {
printf("invalid: %s\n",$0)
next
}
n = $0
printf("factors of %s:",n)
for (i=1; i<=n; i++) {
if (n % i == 0) {
printf(" %d",i)
}
}
printf("\n")
}
</lang>
<p>output:</p>
<pre>
enter a number or C/R to exit
invalid: -1
factors of 0:
factors of 1: 1
factors of 2: 1 2
factors of 11: 1 11
factors of 64: 1 2 4 8 16 32 64
factors of 100: 1 2 4 5 10 20 25 50 100
factors of 32766: 1 2 3 6 43 86 127 129 254 258 381 762 5461 10922 16383 32766
factors of 32767: 1 7 31 151 217 1057 4681 32767
</pre>
=={{header|BASIC}}==
{{works with|QBasic}}
477

edits