Given a number N, the task is to check whether the given number is Armstrong number or not. If the given number is Armstrong Number then print “Yes” else print “No”.
A positive integer of D digits is called an armstrong-numbers of order D (order is the number of digits) if
Where D is number of digit in number N
and N(1), N(2), N(3)… are digit of number N.
Input: N = 153
153 is an Armstrong number.
1*1*1 + 5*5*5 + 3*3*3 = 153
120 is not an Armstrong number.
1*1*1 + 2*2*2 + 0*0*0 = 9
Approach: The idea is to count the number of digits(say d) in the given number N. For every digit(say r) in the given number N find the value of rd and if the summation of all the values is N then print “Yes” else print “No”.
Below is the implementation of the above approach:
Time Complexity: O(log10N)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program for Armstrong Numbers
- Armstrong Numbers between two integers
- XOR and OR of all N-digit Armstrong numbers
- Sum of all armstrong numbers lying in the range [L, R] for Q queries
- C Program to check Armstrong Number
- Range Queries for count of Armstrong numbers in subarray using MO's algorithm
- TCS Coding Practice Question | Check Armstrong Number
- Array Range Queries to find the Maximum Armstrong number with updates
- Program to find GCD or HCF of two numbers
- Program to find LCM of two numbers
- C Program to Swap two Numbers
- Program to find LCM of 2 numbers without using GCD
- Program for Fibonacci numbers
- Program to Add Two Complex Numbers
- Program for harmonic mean of numbers
- Program for Perrin numbers
- C++ Program for GCD of more than two (or array) numbers
- C Program for Fibonacci numbers
- C++ Program for Sum of squares of first n natural numbers
- Program to find first N Fermat Numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.