# Check whether the given number is Armstrong

Check whether the given number is Armstrong

Define a function that check whether the given number is Armstrong.

Aim: A function that check whether the given number is Armstrong

Algorithm:

Step1. Start

Step2. import math

Declare the variable n and read n

Step3. define armstrong function

Step4. In armstrong function

Assign n to a

Initialise sum to 0

Step5. In while Loop, perform

d=n%10

sum+=d*d*d

n=math.floor(n/10)

Step6. check the condition    sum==a

Step7  If the condition is true print that given number is Armstrong number

Step8. otherwise print that given number is not Armstrong number

Step9. Call armstrong (n)  function

Step10. End

Program:

import math

n=int(input(“enter the number:”))

def armstrong(n):

a=n              # 0  1  153  370   371   407

sum=0

while(n!=0):

d=n%10

sum+=d*d*d

n=math.floor(n/10)

if(sum==a):

print(“given number is Armstrong number”)

else:

print(“given number is not Armstrong number”)

armstrong(n)

Ouput:

>>>

enter the number:245

given number is not Armstrong number

>>>

>>>

enter the number:153

given number is Armstrong number

>>>

## Recommended Posts:

Check whether the given number is Armstrong

### Domain & free Hosting

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.