đWhat is an Armstrong number?
- sunreefsquare
- Dec 19, 2022
- 2 min read
Ok we are getting close to Christmas đ and we have a little more time to do quizzesđ§ I can only recommend you, to read this post to the end as I find it both interesting and eventually we learn something.
Also I don't ask to solve an exercise on the PI but on the #Armstrong number!
An Armstrong number is a number such that the sum of the cubes of its digits is equal to the number itself, or is a number that is equal to the sum of its own digits each raised to the power of the number of digits.

For example,
153 is an Armstrong number because 153 = 1^3 + 5^3 + 3^3
371 is an Armstrong number because 371 = 3^3 + 7^3 + 1^3
407 is an Armstrong number because 407 = 4^3 + 0^3 + 7^3
There are a few reasons why you might want to use an Armstrong number:
1ď¸âŁ They are interesting mathematical curiosities and can be fun to work with.
2ď¸âŁ They can be used to test the accuracy of an implementation of a program that performs arithmetic operations.
3ď¸âŁ They can be used as a simple form of encryption, by encoding a message as an Armstrong number and then sending the number to someone else, who can decode the message by finding the original digits of the number.
However, it's important to note that Armstrong numbers are not commonly used in real-world applications, and there are usually more practical ways to achieve thegoals.
So far i hope everybody understands the process!đ
And as a Christmas gift âď¸, I include to this post an nice basic program in JavaScriptđ¨âđť so that the nerds of you can copy the code for example on Visual Studio Code (VSC is for free on Internet) and play the game/quiz with your family!
'use strict';
function checkArmstrongNumber() {
// Prompt the user to enter a number
const num = window.prompt('Enter a number?');
// Convert the number to a string and get the length
const numString = num.toString();
const numLength = numString.length;
// Initialize a sum to keep track of the total
let sum = 0;
// Loop through each digit of the number
for (let i = 0; i < numLength; i++) {
// Get the current digit
const digit = parseInt(numString[i]);
// Add the cube of the digit to the sum
sum += digit ** 3;
}
// Check if the sum is equal to the original number
if (sum === num) {
console.log(`${num} đis an Armstrong number đĽđ`);
} else {
console.log(`${num} is not an Armstrong number đĽş`);
}
}
checkArmstrongNumber();
I hope that some of you will try this code and if you have any comments or questions about the program please fell free to contact me.
Comments