Narcissistic decimal number: Difference between revisions

no edit summary
m (→‎{{header|REXX}}: changed some comments and whitespace, added comments to a REXX section header, used templates for the output sections.)
No edit summary
Line 799:
"Elapsed time: 186430.429966 msecs"
(0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 548834 1741725 4210818 9800817 9926315)
</pre>
 
=={{header|COBOL}}==
<lang COBOL>
PROGRAM-ID. NARCISSIST-NUMS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 num-length PIC 9(2) value 0.
01 in-sum PIC 9(9) value 0.
01 counter PIC 9(9) value 0.
01 current-number PIC 9(9) value 0.
01 temp PIC 9(9) value 0.
01 modulo PIC 9(9) value 0.
01 answer PIC 9 .
PROCEDURE DIVISION.
MAIN-PROCEDURE.
DISPLAY "the first 20 narcissist numbers:" .
MOVE 20 TO counter.
PERFORM UNTIL counter=0
PERFORM 000-NARCISSIST-PARA
IF answer = 1
SUBTRACT 1 from counter
GIVING counter
DISPLAY current-number
END-IF
ADD 1 TO current-number
END-PERFORM
STOP RUN.
000-NARCISSIST-PARA.
MOVE ZERO TO in-sum.
MOVE current-number TO temp.
COMPUTE num-length =1+ FUNCTION Log10(temp)
PERFORM UNTIL temp=0
DIVIDE temp BY 10 GIVING temp
REMAINDER modulo
COMPUTE modulo=modulo**num-length
ADD modulo to in-sum GIVING in-sum
END-PERFORM.
IF current-number=in-sum
MOVE 1 TO answer
ELSE MOVE 0 TO answer
END-IF.
END PROGRAM NARCISSIST-NUMS.
</lang>
 
{{out}}
<pre>
the first 20 narcissist numbers:
000000000
000000001
000000002
000000003
000000004
000000005
000000006
000000007
000000008
000000009
000000153
000000370
000000371
000000407
000001634
000008208
000009474
000054748
000092727
000093084
 
</pre>