English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a C program perfect that determines if parameter number is a perfect number and determines and prints all the perfect numbers between 1 and 1000. Print the factors of each perfect number to confirm that the number is indeed perfect. Challenge the power of your computer by testing numbers much larger than 1000.

2007-03-24 01:53:21 · 3 answers · asked by soultosoul17 1 in Computers & Internet Programming & Design

3 answers

check here somewhere
it is already asked and answered

2007-03-24 02:37:06 · answer #1 · answered by abd 5 · 0 0

This is really about how to find the factors of any integer. I suggest you do it recursively.

factors(36) = {2, factors(18)}
factors(18) = {2, factors(9)}
factors(9) = {3, factors(3)}
factors(3) = 3

I also suggest you use Fermat's little theorem to first test if a number is prime or not, or else you'll end up doing a lot of divisions only to find that the number is prime.

I'm sure there is some elegant better way to do this but this is the one that comes off the top of my head right now. Use one of these: http://en.wikipedia.org/wiki/Integer_factorization

2007-03-24 09:53:01 · answer #2 · answered by icnintel 4 · 0 0

You're asking us to do your homework for you? Shame on you!

2007-03-24 09:09:07 · answer #3 · answered by CinderBlock 5 · 1 0

fedest.com, questions and answers