0
How to make a program in "C" to find your typed number is Armstrong number or not.
Inputs should be valid for every number of digits
1 Réponse
+ 3
You will want to start by designing a function that returns the number of digits of its parameter. Once you have that, it's easy, really. As variables, you need the number, a copy of the number you can perform the maths on, the result and the amount of digits. Have a loop run while the number is not equal to 0, and inside, access the last digit with number % 10, raise it to the power of the amount of digits (the header <math.h> will come in handy here) and add that to the result. Lastly, divide the number by 10. If the loop finishes, check if the result is equal to the copy of the number, and that's it, then.
Also, you can look for reference programs here:
https://www.sololearn.com/learn/4708/?ref=app