Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions

Content added Content deleted
(added AWK)
Line 203: Line 203:
<pre>22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555
<pre>22 33 44 48 55 66 77 88 99 122 124 126 155 162 168 184 222 244 248 264 288 324 333 336 366 396 412 424 444 448 488 515 555
636 648 666 728 777 784 824 848 864 888 936 999</pre>
636 648 666 728 777 784 824 848 864 888 936 999</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f NUMBERS_DIVISIBLE_BY_THEIR_INDIVIDUAL_DIGITS_BUT_NOT_BY_THE_PRODUCT_OF_THEIR_DIGITS.AWK
# converted from C
BEGIN {
start = 1
stop = 999
for (i=start; i<=stop; i++) {
if (divisible(i)) {
printf("%4d%1s",i,++count%10?"":"\n")
}
}
printf("\nNumbers divisible by their individual digits but not by the product of their digits %d-%d: %d\n",start,stop,count)
exit(0)
}
function divisible(n, c,d,p) {
p = 1
for (c=n; c; c=int(c/10)) {
d = c % 10
if (!d || n % d) { return(0) }
p *= d
}
return(n % p)
}
</lang>
{{out}}
<pre>
22 33 44 48 55 66 77 88 99 122
124 126 155 162 168 184 222 244 248 264
288 324 333 336 366 396 412 424 444 448
488 515 555 636 648 666 728 777 784 824
848 864 888 936 999
Numbers divisible by their individual digits but not by the product of their digits 1-999: 45
</pre>


=={{header|BASIC}}==
=={{header|BASIC}}==