Check Armstrong Number in Python

 

         Check Armstrong Number in Python

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153  is an Armstrong


Program:

sum=0;rem=0;
num=int(input("Enter a Number"))

temp= num;

while (num != 0):
   
      rem = num % 10;
      sum = sum + (rem*rem*rem);
      num = num // 10;
   

if(temp == sum):
      print(temp," is an Armstrong Number");
else:
      print(temp,"is not an Armstrong Number");



OutPut:
Enter a Number153
153  is an Armstrong Number








No comments:

Post a Comment