We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dc0a515 commit b085575Copy full SHA for b085575
armstrong.py
@@ -0,0 +1,36 @@
1
+def power(x, y):
2
+
3
+ if y == 0:
4
+ return 1
5
+ if y % 2 == 0:
6
+ return power(x, y // 2) * power(x, y // 2)
7
8
+ return x * power(x, y // 2) * power(x, y // 2)
9
10
+def order(x):
11
12
+ n = 0
13
+ while (x != 0):
14
+ n = n + 1
15
+ x = x // 10
16
17
+ return n
18
19
+def isArmstrong(x):
20
21
+ n = order(x)
22
+ temp = x
23
+ sum1 = 0
24
25
+ while (temp != 0):
26
+ r = temp % 10
27
+ sum1 = sum1 + power(r, n)
28
+ temp = temp // 10
29
30
+ return (sum1 == x)
31
32
+x = 153
33
+print(isArmstrong(x))
34
35
+x = 1253
36
0 commit comments