Anonymous user
Sum of the digits of n is substring of n: Difference between revisions
Sum of the digits of n is substring of n (view source)
Revision as of 17:57, 20 June 2021
, 3 years ago→{{header|Nim}}
(→{{header|ALGOL W}}: spell isContained properly...) |
|||
Line 912:
918
919</pre>
=={{header|Nim}}==
<lang Nim>import strutils
func digitsum(n: Natural): int =
if n == 0: return 0
var n = n
while n != 0:
result += n mod 10
n = n div 10
var count = 0
for n in 0..<1000:
let sn = $n
if $digitsum(n) in sn:
inc count
stdout.write sn.align(3), if count mod 8 == 0: '\n' else: ' '</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|Perl}}==
|