Discuss Need help with program in the C Programming forum on Dev Shed. Need help with program C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 17 m 35 sec
Reputation Power: 0
Need help with program
Ok so the assignment is:
"Write a program that asks for an integer input ‘n’ and print all integer numbers of n-digits for which the sum of the
digits of the number, to the power of three, is equal to the number itself.
For instance, for n=2, check all numbers in the range of 10 – 99. e.g 37 = 3^3+7^3"
And I'd like some help on how to do this with explanation.
Time spent in forums: 1 Month 1 Week 2 h 12 m 42 sec
Reputation Power: 1312
Originally Posted by b49P23TIvg
Interesting problem. We might ask
Are there a finite number of such numbers?
How does the answer change if we express n in a different base?
Of course there's only a finite number: an n-digit number is at least 10^(n-1). The sum of the cubes of the digits is at most (9^3)*n = 729*n. If n is at least 5, then 10^(n-1) is always greater than 729*n (exercise for the reader). Therefore, all such numbers must have fewer than 5 digits, so there can be at most 10,000 such numbers, QED.