PHP | Check if a number is armstrong number
Given a number, we need to check whether it is an armstrong number or not in PHP. An Armstrong number is the one whose value is equal to the sum of the cubes of its digits.
Input : 407 Output : Yes 407 = (4*4*4) + (0*0*0) + (7*7*7) = 64 + 0 + 343 = 407 Input : 303 Output : No
Approach: For every digit r in input number x, compute r3. If sum of all such values is equal to n, then print “Yes”, else “No”.
Time Complexity: O(num), where num is the number of digits in the given number.
My Personal Notes arrow_drop_up
Please Login to comment...