what is armstrong number

what is armstrong number

1 year ago 44
Nature

An Armstrong number is a number that is equal to the sum of its digits each raised to the power of the number of digits in the number. In other words, if you take each digit in the number, raise it to the power of the total count of digits in the number, and then sum them all together, the result is the original number itself. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. Armstrong numbers are also known as narcissistic numbers.

Armstrong numbers can be found using a program that checks whether the sum of the digits raised to the power of the number of digits equals the original number. For example, the following Python program determines whether the integer entered is an Armstrong number or not:

def no_of_digits(num):
    i = 0
    while num > 0:
        num //= 10
        i+=1
    return i

def required_sum(num):
    i = no_of_digits(num)
    s = 0
    while num > 0:
        digit = num % 10
        num //= 10
        s += pow(digit, i)
    return s

num = int(input("Enter number:"))
s = required_sum(num)
if s == num:
    print("Armstrong Number")
else:
    print("Not Armstrong Number")

Armstrong numbers can also be generated using a program that computes all Armstrong numbers in a given range. For example, the following program computes all Armstrong numbers in the range of 0 and 999:

PROGRAM ArmstrongNumber
IMPLICIT NONE
INTEGER :: a, b, c ! the three digits
INTEGER :: abc, a3b3c3 ! the number and its cubic sum
INTEGER :: Count ! a counter
Count = 0
DO a = 0, 9 ! for the left most digit
   DO b = 0, 9 ! for the middle digit
      DO c = 0, 9 ! for the right most digit
         abc = a*100 + b*10 + c ! the number
         a3b3c3 = a**3 + b**3 + c**3 ! the sum of cubes
         IF (abc == a3b3c3) THEN ! if they are equal
            Count = Count + 1 ! count and display it
            WRITE(*,*) Armstrong number , Count, : ... , abc
         END IF
      END DO
   END DO
END DO
END PROGRAM ArmstrongNumber

In summary, an Armstrong number is a number that is equal to the sum of its digits each raised to the power of the number of digits in the number. Armstrong numbers can be found using programs that check whether the sum of the digits raised to the power of the number of digits equals the original number or that compute all Armstrong numbers in a given range.

Read Entire Article