Sum of the digits of n is substring of n: Difference between revisions
Content added Content deleted
(added Perl programming solution) |
Not a robot (talk | contribs) (→{{header|BASIC}}: fix the bugs) |
||
Line 43: | Line 43: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{incorrect|BASIC|wrong output, last should be 919<br><br>suspect I mod 10 shd be K mod 10}} |
|||
<lang basic>10 DEFINT I,J,K |
<lang basic>10 DEFINT I,J,K |
||
20 FOR I=0 TO 999 |
20 FOR I=0 TO 999 |
||
30 J=0: K=I |
30 J=0: K=I |
||
40 IF K>0 THEN J=J+ |
40 IF K>0 THEN J=J+K MOD 10: K=K\10: GOTO 40 |
||
41 I$=STR$(I): I$=RIGHT$(I$,LEN(I$)-1) |
|||
42 J$=STR$(J): J$=RIGHT$(J$,LEN(J$)-1) |
|||
50 IF INSTR(I$,J$) THEN PRINT I, |
|||
60 NEXT I</lang> |
60 NEXT I</lang> |
||
{{out}} |
{{out}} |
||
<pre> 0 1 2 3 4 |
<pre> 0 1 2 3 4 |
||
5 6 7 8 9 |
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}}== |