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 22:35, 26 June 2021
, 2 years agoAdded XPL0 example.
m (added the word "decimal" to the task's requirements, added a comma.) |
(Added XPL0 example.) |
||
Line 1,465:
48 such numbers found.
</pre>
=={{header|XPL0}}==
<lang XPL0>func Check(N); \Return 'true' if sum of digits of N is a substring of N
int N, Sum, A, B, C;
[N:= N/10;
C:= rem(0);
N:= N/10;
B:= rem(0);
A:= N;
Sum:= A+B+C;
if Sum=A or Sum=B or Sum=C then return true;
if Sum = B*10 + C then return true;
if Sum = A*10 + B then return true;
return false;
];
int Count, N;
[Count:= 0;
for N:= 0 to 1000-1 do
if Check(N) then
[IntOut(0, N);
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
CrLf(0);
IntOut(0, Count);
Text(0, " such numbers found below 1000.
");
]</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
48 such numbers found below 1000.
</pre>
|