Write a program for the Armstrong number
let sum = 0;
const number = prompt('Enter a three-digit positive integer: ');
let tempNumber = number;
while (tempNumber > 0) {
let remainder = tempNumber % 10;
sum += remainder * remainder * remainder;
tempNumber = parseInt(tempNumber / 10);
}
if (sum == number) {
console.log(`${number} is an Armstrong number`);
}
else {
console.log(`${number} is not an Armstrong number.`);
}
Comments
Leave a comment