Posts

Showing posts with the label amstrong number

Amstrong number in python

Image
Amstrong number in python An n digit number is called an amstrong number if, the number is equal to the sum  of nth power of its digits. abc.. = a n + b n + c n + .. An amstrong number is also called as  narcissistic number.  A three digit number is called an Armstrong number if the number is equal to the sum of the cubes of its digits.  For example, 370 is an amstrong number as,  3 3 + 7 3 + 0 3 = 370. Here's a python program to check whether a number is amstrong number or not. Procedure : 1. Start. 2. Define a function to count the digits of a number. 3. Get the number as input from the user. 4. Assign n to a temporary variable. 5. Count the number of digits of the number using the count digits function. 6. Initialize sum as 0. 7. loop until temp = 0     => get the last digit of the number.     => calculate the nth power of the last digit.     => add the nth power of number to the sum.     =>  remove the last digit from the number 8. check if the sum is equal t