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 09:09, 14 April 2021
, 3 years agoadd FreeBASIC
(→{{header|REXX}}: added the computer programming language REXX.) |
(add FreeBASIC) |
||
Line 4:
Find and show numbers n with property that the sum of the digits of n is substring of n, where '''n < 1000'''
<br><br>
=={{header|FreeBASIC}}==
<lang freebasic>function is_substring( s as string, j as string ) as boolean
dim as integer nj = len(j), ns = len(s)
for i as integer = 1 to ns - nj + 1
if mid(s,i,nj) = j then return true
next i
return false
end function
function sumdig( byval n as integer ) as integer
dim as integer sum
do
sum += n mod 10
n \= 10
loop until n = 0
return sum
end function
for i as uinteger = 0 to 999
if is_substring( str(i), str(sumdig(i))) then print i;" ";
next i : print : end</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|REXX}}==
|