Sunday, 12 February 2023

Python program to check if the given number is Armstrong number or not

 Python program to check Armstrong number

In this program we are implementing logic to check for n-digit Armstrong number.

Program

n=int(input('Enter a number '))
def count(n):
    c=0
    while(n>0):
        c+=1
        n=n//10
    return c
temp=n
arm=0
while(temp>0):
    arm+=(temp%10)**count(n)
    temp//=10
if(arm==n):
    print('The given number {0} is an armstrong number.'.format(n))
else:
    print('The given number {0} is not an armstrong number.'.format(n))
Output 1
Enter a number 371
The given number 371 is an armstrong number.
Output 2
Enter a number 150
The given number 150 is not an armstrong number.
Output 3
Enter a number 54748
The given number 54748 is an armstrong number.

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top