Armstrong Number



                      
                      An Armstrong number is a digit is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 370 is an Armstrong number since 3**3 + 7**3 + 0**3 = 370.
           To write a code in python we use logic to separate the integer number from the given number. Use modulo (%) to separate the integers, then we use the sum variable to add and calculate the cube of the appropriate number and so on.


Python code For Armstrong Number:
def Armstrong_no(x):
 no=x
 sum=0
 while no>0:
    R=no%10
    sum=sum+(R*R*R)
    no=no//10
 if num==sum:
    print(num,"is an Armstrong number")
 else:
    print(num,"is not an Armstrong number")
   

num=int(input("Enter a number: "))
Armstrong_no(num)

Output:
Enter a number: 370
370 is an Armstrong number

Enter a number: 457
457 is not an Armstrong number
Armstrong Number Armstrong Number Reviewed by Amit Waghmare on November 23, 2019 Rating: 5

No comments: