Armstrong Number added

This commit is contained in:
Shyamashrita 2020-10-02 14:17:21 +05:30
parent 07bc4a4b97
commit 1718c91ed6

View File

@ -0,0 +1,22 @@
// Check Armstrong Number of n Digits
let number = prompt("Enter a positive integer");
let numberOfDigits = number.length;
let sum = 0;
let temp = number;
while (temp > 0) {
let remainder = temp % 10;
sum += remainder ** numberOfDigits;
temp = parseInt(temp / 10);
if (sum == number) {
console.log(`${number} is an Armstrong number`);
}
else {
console.log(`${number} is not an Armstrong number.`);
}