Day 41: Armstrong Number or not of 100DaysCodingChallenge
Hello all,
#day41
Day41
Today's my task was to Write a Program to check whether a number entered by the user is an Armstrong number or not.
I have started the 100 days of coding challenge to improve my programming skills..
Code :
// program to check an Armstrong number of three digits // const number = prompt('Enter a three-digit positive integer : '); let number = prompt("Enter a Number : "); let sum = 0; // create a temporary variable let temp = number; while (temp > 0) { // finding the one's digit let remainder = temp % 10; sum += remainder * remainder * remainder; // removing last digit from the number temp = parseInt(temp / 10); // convert float into integer } // check the condition if (sum == number) { console.log(`${number} is an Armstrong Number.`); } else { console.log(`${number} is not an Armstrong Number.`); }
Output :
Happy Coding:)
Thank you...
Comments
Post a Comment