Table of Contents
show
Example 17
Write a JavaScript program to check whether a number is Armstrong or not
const prompt = require("prompt-sync")();
let number = prompt("Enter any number : ");
number = parseInt(number);
let temp = number;
let sum = 0;
while (temp > 0) {
rem = temp % 10;
sum = sum + rem * rem * rem;
temp = parseInt(temp / 10);
}
if (sum == number) {
console.log(`${number} is Armstrong Number`);
} else {
console.log(`${number} is not Armstrong Number`);
}
Output
Views: 116