Answer to Question #264591 in HTML/JavaScript Web Application for swsq

Question #264591
Write a program for the Armstrong number




1
Expert's answer
2021-11-15T12:36:48-0500
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.`);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS