68.2k views
0 votes
Write a program to find all three-digit positive integers such that the sum of the cubes of the decimal digits are equal to the number itself

1 Answer

5 votes

Final answer:

The student's question pertains to a programming challenge of finding three-digit numbers that are equal to the sum of the cubes of their digits. A sample Python program demonstrates the logic needed to find these Armstrong numbers, using basic arithmetic operations and a loop structure to test each three-digit number.

Step-by-step explanation:

The student is asking for a program that can identify three-digit numbers where the sum of the cubes of their digits is equal to the number itself. This is a classic programming problem related to the cubing of exponentials and is often associated with Armstrong numbers or narcissistic numbers in number theory. An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits in the number.

Let's consider a three-digit number 'XYZ', where X, Y, and Z represent digit places. Mathematically, we can express the requirement as follows: X^3 + Y^3 + Z^3 = XYZ. For instance, for the number 153, we have 1^3 + 5^3 + 3^3 = 1 + 125 + 27, which equals 153.

Here's a simple Python program that could be written to find such numbers:

for i in range(100, 1000):
x = i // 100
y = (i // 10) % 10
z = i % 10
if (x**3 + y**3 + z**3) == i:
print(i)

This is a complete program that loops over all three-digit numbers, decomposes them into their individual digits, cubes each digit, sums those cubes, and then compares that sum to the original number, printing out the number if it matches the criteria.

User Bill Campbell
by
7.3k points