Sum of the digits of n is substring of n: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add CLU) |
(Added solution for Action!) |
||
Line 156: | Line 156: | ||
918 |
918 |
||
919</pre> |
919</pre> |
||
=={{header|Action!}}== |
|||
<lang Action!>INT FUNC SumDigits(INT num) |
|||
INT res,a |
|||
res=0 |
|||
WHILE num#0 |
|||
DO |
|||
res==+num MOD 10 |
|||
num=num/10 |
|||
OD |
|||
RETURN (res) |
|||
BYTE Func IsValidNumber(INT num) |
|||
CHAR ARRAY s(5),sub(5) |
|||
INT sum,v,len,start |
|||
sum=SumDigits(num) |
|||
StrI(num,s) |
|||
FOR len=1 TO s(0) |
|||
DO |
|||
FOR start=1 TO s(0)-len+1 |
|||
DO |
|||
SCopyS(sub,s,start,start+len-1) |
|||
IF ValI(sub)=sum THEN |
|||
RETURN (1) |
|||
FI |
|||
OD |
|||
OD |
|||
RETURN (0) |
|||
PROC Main() |
|||
INT i,count=[0] |
|||
FOR i=0 TO 999 |
|||
DO |
|||
IF IsValidNumber(i) THEN |
|||
PrintI(i) Put(32) |
|||
count==+1 |
|||
FI |
|||
OD |
|||
PrintF("%E%EThere are %I numbers",count) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Sum_of_the_digits_of_n_is_substring_of_n.png Screenshot from Atari 8-bit computer] |
|||
<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 |
|||
There are 48 numbers |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |