Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Find Armstrong number

Find Armstrong number

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

Loading

Views: 116

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments