arrays - Armstrong Numbers using JavaScript -
this not question, more of public help... given assignment find armstrong numbers within 100 (there 0 , 1) assignment. searched internet find such program, none. methods arrays , other stuff available , didn't have time asking , getting script done... so, here give javascript program finding armstrong numbers... know method redundant, , if have better idea in mind, please share...
thank you.
var = []; var b = new array(); (var ii = 0; ii < 3; ii++) { b[ii] = new array(1001); (var j = 0; j < 1001; j++) { a[j] = 0; b[ii][j] = 0; } } for(var = 0; < 1001; i++) { a[i] = i; b[0][i] = a[i] % 10; b[1][i] = math.floor(i / 10); b[1][i] = b[1][i] % 10; b[2][i] = math.floor(i / 100); b[2][i] = b[2][i] % 10; if (i === math.pow(b[0][i], 3) + math.pow(b[1][i], 3) + math.pow(b[2][i], 3)) { console.log(i + " armstrong number."); } }
Comments
Post a Comment