![]() |
VOOZH | about |
Given a number n, the task is to check whether it is an Armstrong number or not. An Armstrong number is a number that is equal to the sum of its digits raised to the power of the total number of digits. For example:
Input: n = 153
Output: Armstrong Number
Explanation: 13 + 53 + 33 = 153
Let’s explore different methods to check Armstrong numbers.
This approach extracts digits using arithmetic operations and calculates the sum of digits raised to the required power. The final sum is then compared with the original number.
Armstrong Number
Explanation:
This approach converts the number into a string and loops through each digit directly. Each digit is converted back to an integer for calculation.
Armstrong Number
Explanation:
This approach uses map() and lambda to process each digit and calculate the Armstrong sum in a compact way.
Armstrong Number
Explanation:
This approach calculates the Armstrong sum recursively by processing one digit at a time until the number becomes 0.
Armstrong Number
Explanation: