मराठी

Write a program to input any number and check whether given number is Armstrong or not.

Advertisements
Advertisements

प्रश्न

Write a program to input any number and check whether given number is Armstrong or not.

कोड लेखन
Advertisements

उत्तर

For a three-digit Armstrong number, add the cubes of its digits and compare the sum with the original number.

n = int(input("Enter any number: "))
original = n
sum_of_cubes = 0

while n > 0:
    digit = n % 10
    sum_of_cubes += digit ** 3
    n //= 10

if sum_of_cubes == original:
    print("Armstrong number")
else:
    print("Not an Armstrong number")
 
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1: Review of Phython - EXERCISE [पृष्ठ २६]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
पाठ 1 Review of Phython
EXERCISE | Q 11. | पृष्ठ २६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×