Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
September 17th, 2012, 12:41 PM
 fireflashx32
Registered User

Join Date: Sep 2012
Posts: 1
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.

Yours sincerely, fireflashx32
b49P23TIvg agrees: I agree that the comma of "number, to" implies that the equation should be pow((sum of digits of
n),3)==n . Confusing.

#2
September 17th, 2012, 01:36 PM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,266
Time spent in forums: 2 Months 4 Weeks 1 Day 18 h 35 m 56 sec
Reputation Power: 1827
So what bit is confusing you?

- Reading in a number n ?
- counting from pow(10,n-1) to pow(10,n)-1 ?
- extracting digits from x ?
- calculating the sum of two cubes ?

Show us what steps you CAN achieve for yourself, then post a question about your code.

This isn't a homework dumping site.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

#3
September 17th, 2012, 01:55 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,216
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 32 m 42 sec
Reputation Power: 455

Are there a finite number of such numbers?

How does the answer change if we express n in a different base?
__________________
[code]Code tags[/code] are essential for python code!

#4
September 17th, 2012, 03:52 PM
 Lux Perpetua
Contributing User

Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,939
Time spent in forums: 1 Month 1 Week 3 h 27 m 29 sec
Reputation Power: 1312
Quote:
 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.
b49P23TIvg agrees: Way to solve the readers' exercise!

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Need help with program