what is armstrong number:-
An armstrong number is a number which equal to the sum of the power of number of digits of its individual digits.
For example, 153 is an armstrong number as −
153 has 3 digits
153 = (1)3 + (5)3 + (3)3 153 = 1 + 125 + 27 153 = 153
2) 1634 has 4 digits so power of all number are 4.
1634 = 1^4 + 6^4 + 3^4 + 4^4
1634 = 1 + 1296 + 81 + 256
1634 = 1634
So it is also a armstrong number.
3) 54748 has five digits so power of all digits are 5
54748=5^5 + 4^5 + 7^5 + 4^5 + 8^5
54748= 3125 + 1024 + 16807 + 1024 + 32768
54748= 54748
So it is a armstrong number.
code:-
num=int(input("enter a number"))n1=numn2=num# for calculating number of digits
no_di=0while n1!=0: no_di=no_di+1 n1=n1//10
# logic for checking for armstrong numbersum=0while n2!=0: r=n2%10 sum=sum+pow(r,no_di) n2=n2//10if(num==sum): print("Armstrong number")else: print("Not a Armstrong number")
num=int(input("enter a number"))
n1=num
n2=num
# for calculating number of digits
no_di=0
while n1!=0:
no_di=no_di+1
n1=n1//10
# logic for checking for armstrong number
sum=0
while n2!=0:
r=n2%10
sum=sum+pow(r,no_di)
n2=n2//10
if(num==sum):
print("Armstrong number")
else:
print("Not a Armstrong number")
Output:-
enter a number153
Armstrong number
enter a number123
Not a Armstrong number
1 Comments
💯💯
ReplyDelete