Computer Science, asked by dayaladitya3976, 1 year ago

Write a Python program to check if a given number is an Armstrong number.

Answers

Answered by ramesh87901
8

Python Program to Check Armstrong Number

Armstrong number:

A number is called Armstrong number if it is equal to the sum of the cubes of its own digits.

example: 153 is an Armstrong number since 153 = 1*1*1 + 5*5*5 + 3*3*3.

The Armstrong number is also known as narcissistic number.

Example:

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

sum = 0  

temp = num  

 

while temp > 0:  

  digit = temp % 10  

  sum += digit ** 3  

  temp //= 10  

 

if num == sum:  

  print(num,"is an Armstrong number")  

else:  

  print(num,"is not an Armstrong number")  

Output:

see the attached picture.

Attachments:

ASweety1431: excuse me
ASweety1431: can u help me plzzz ??
ramesh87901: help. on what ????
ramesh87901: tell me
ASweety1431: u know Python programming language ???
ramesh87901: i dont know
ramesh87901: whyy
ASweety1431: okk then leave
Answered by sushiladevi4418
0

Answer:

Python Program For Armstrong Numbers.

Explanation:

##Python Program For Armstrong Numbers.

Number = int(input("\n Please Enter the Number to Check for Armstrong: "))

# Initializing Sum and Number of Digits

Sum = 0

Times = 0

# Calculating Number of individual digits

Temp = Number

while Temp > 0:

Times = Times + 1

Temp = Temp // 10

# Finding Armstrong Number

Temp = Number

while Temp > 0:

Reminder = Temp % 10

Sum = Sum + (Reminder ** Times)

Temp //= 10

if Number == Sum:

print("\n %d is Armstrong Number.\n" %Number)

else:

print("\n %d is Not a Armstrong Number.\n" %Number)

Similar questions