How to Find Armstrong Numbers between two given Integers

How to Find Armstrong Numbers between two given Integers

An integer is referred to as the Armstrong numbers of the order n. When it’s each digit is separated, cubed, and added together then it will result in a sum that is the same as the number, (i.e., pqrs… = pn + qn + rn + sn +…).

If there is an Armstrong number with three digits, the total of cubes in each number is equal to the number in itself.

Example:

In this tutorial, we will learn how we can find Armstrong numbers between two given integers by using Python language.

For example:

The method we use below is easy. We look through all numbers within the range. For each number, we first determine the number of digits within it. Make the total number of decimal digits of the current number be the number “n”. Then we calculate the sum of the” n-th” power of each digit. If the sum is greater than “K”, then we record the result.

Code:

Output:

Please enter the lower range of the integer:  1000
Please enter the upper range of the integer:  10000
The Armstrong Numbers Between Two Given Integers:
1634
8208
9474

Conclusion

In this tutorial, we have discussed how to print Armstrong numbers between two given integers using Python programming.


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263270.html

(0)
上一篇 2022年5月30日
下一篇 2022年5月30日

相关推荐

发表回复

登录后才能评论