Computer Science, asked by Anonymous, 11 months ago

wap to print Armstrong no.​

Answers

Answered by AbhijithPrakash
6

# First of all you'll need to know what is Armstrong number.

# Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371, 407.

# Now as you know what is it, lets start to code.

# First I'll take 3 variables "n", "sum", and "N".

n = int(input("Enter any number : "))

sum = 0

N = n

# Using a while loop for N.

while N > 0:

  digit = N % 10  # I took a variable "digit" whose value will change to the remainder of the current value of N when divided by 10.

  sum += digit ** 3  # "sum" will get equal to the sum of sum and digit to the power 3.

   N //= 10 # '//=' is called "Floor Division AND"

if (n == sum):

  print(n,"is an Armstrong number!")

else:

  print(n,"is not an Armstrong number!")

Attachments:
Similar questions