Jump to content

Self numbers: Difference between revisions

m
→‎first 50 self numbers: added a feature to the program.
m (→‎first 50 self numbers: added/changed whitespace and comments.)
m (→‎first 50 self numbers: added a feature to the program.)
Line 997:
parse arg n . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n= 50 /*Not specified? Then use the default.*/
tell = n>0; n= abs(n)
@.= . /*initialize the array of self numbers.*/
do j=1 for n*10 /*scan through ten times the #s wanted.*/
$= j /*1st part of sum is the number itself.*/
do k=1 for length(j) /*sum the decimal digits in the number.*/
$= $ + substr(j, k, 1) /*add a particular digit to the sum. */
end /*k*/
@.$= /*mark J as not being a self number. */
end /*j*/
list= 1 /*initialize the list to the 1st number*/
#= 1 /*the count of self numbers (so far). */
Line 1,011 ⟶ 1,012:
end /*i*/
 
say 'the firstn ' n " self numbers were found." self numbers are:" /*display the title for the output list*/
say list if tell then say list /*display list of self numbers ──►term.*/
exit 0 /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
the first 50 self numbers are:were found.
1 3 5 7 9 20 31 42 53 64 75 86 97 108 110 121 132 143 154 165 176 187 198 209 211 222 233 244 255 266 277 288 299 310 312 323 334 345 356 367 378 389 400 411 413 424 435 446 457 468
</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.