forked from N-PCs/PYTHON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
armstrong_number.py
63 lines (37 loc) · 1.05 KB
/
armstrong_number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Q1 write a program to print all armstrong number between 100 to 999
# Q2 write a program to print following
#*****
#****
#***
#**
#*
# Q3 write a program to convert one decimal number to binary number without using bin function
#SOLUTIONS
#Q1 ans.
for n in range(100,1000):
a=n//100
b=(n//10)%10
c=n%10
s=(a*a*a)+(b*b*b)+(c*c*c)
if n==s:
print(n)
# Q2 ans
n=int(input("enter the number--> "))
for i in range(n,0,- 1):
print('*'*i)
#OR
n=int(input("enter the number--> "))
for i in range(0,n+1):
print('*'*(n-i)
# Q3 ANS
def dtob(number):
binary_string = ""
while number > 0:
remainder = number % 2
binary_string = str(remainder) + binary_string
number //= 2
return binary_string
decimal_num = int(input("Enter a decimal number: "))
binary_num = dtob(decimal_num)
print("Binary equivalent:", binary_num)
# this program can be written by recursive function also