Skip to content

Commit 34e21e5

Browse files
authored
To Find Armstrong Number in an Interval
An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.
1 parent 99cf7d7 commit 34e21e5

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Program to check Armstrong numbers in a certain interval
2+
3+
lower = 100
4+
upper = 2000
5+
6+
for num in range(lower, upper + 1):
7+
8+
# order of number
9+
order = len(str(num))
10+
11+
# initialize sum
12+
sum = 0
13+
14+
temp = num
15+
while temp > 0:
16+
digit = temp % 10
17+
sum += digit ** order
18+
temp //= 10
19+
20+
if num == sum:
21+
print(num)

0 commit comments

Comments
 (0)