Created
November 28, 2019 13:00
-
-
Save ma-9/6469c8bd75c899f4a31bb82554a06d4b to your computer and use it in GitHub Desktop.
Console Program to Find ArmStrong Numbers in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ArmStrong Numbers are 0,1, 153, 370, 371 and 407 | |
let n = 153; | |
let r, | |
temp, | |
sum = 0; | |
temp = n; | |
while (n > 0) { | |
r = n % 10; | |
sum = sum + r * r * r; | |
n = Math.floor(n / 10); | |
} | |
if (temp == sum) { | |
console.log('ArmStrong Number'); | |
} else { | |
console.log('Non ArmStrong Number'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment