Narcissistic decimal number: Difference between revisions

Line 772:
{{out}}
<pre>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|JavaScript}}==
{{trans|Java}}
<lang javascript>function isNarc(x) {
var str = x.toString(),
i,
sum = 0,
l = str.length;
if (x < 0) {
return false;
} else {
for (i = 0; i < l; i++) {
sum += Math.pow(str.charAt(i), l);
}
}
return sum == x;
}
function main(){
var n = [];
for (var x = 0, count = 0; count < 25; x++){
if (isNarc(x)){
n.push(x);
count++;
}
}
return n.join(' ');
}</lang>
{{out}}
<pre>"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|MATLAB}}==
Anonymous user