Sum of the digits of n is substring of n: Difference between revisions

Content added Content deleted
(Add ALGOL-M)
(Add BCPL)
Line 308: Line 308:
917 918 919
917 918 919
</pre>
</pre>

=={{header|BCPL}}==
<lang bcpl>get "libhdr"

let dsum(n) = n=0 -> 0, n rem 10 + dsum(n/10)

let chop(n) = valof
$( let i=1
while i<n do i := i * 10
i := i / 10
resultis i=0 -> 0, n rem i
$)

let infix(n,h) =
n = h -> true,
h = 0 -> false,
infix(n,h/10) -> true,
infix(n,chop(h)) -> true,
false

let start() be
$( let c=0
for i=0 to 999 do
$( if infix(dsum(i),i) then
$( writef("%I5",i)
c := c + 1
if c rem 10=0 then wrch('*N')
$)
$)
wrch('*N')
$)</lang>
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
10 20 30 40 50 60 70 80 90 100
109 119 129 139 149 159 169 179 189 199
200 300 400 500 600 700 800 900 910 911
912 913 914 915 916 917 918 919</pre>


=={{header|C}}==
=={{header|C}}==