![]() |
|
#1
|
|||
|
|||
"Perfect" numbers - help with code/algorithm?Hi everyone,
I'm trying to code a program that will calculate 'perfect numbers'. ( A perfect number is any positive integer that is equal to the sum of its divisors < n. ) The program is meant to scan an interval [a, b] and return the smallest number that is the closest to its sum of divisors. e.g Whats its meant to look like: Enter 2 positive integers a <= b: 2 28 The distance is minimal for 6 and is equal to 0 Here is the code... CPP / C++ / C Code:
Is there something wrong with my implementation? I have a feeling that my formulae function is incorrect, but I have no idea where to begin. Any help is appreciated. |
|||
|
#3
|
|||
|
|||
Re: "Perfect" numbers - help with code/algorithm?Yes, but I believe that post refers to finding actual perfect numbers. This question is finding an ALMOST perfect number within a range of integers that has divisors that add up almost to the number itself and then also displaying the difference in the number and the sum of the divisors.
Personally I get completely lost with the use of d. I do not quite get why d is equal to a, and yet d is equal to 2 in the function sum. |
|
#4
|
||||
|
||||
Re: "Perfect" numbers - help with code/algorithm?Quote:
Quote:
Quote:
Now how many of the above steps have you done in your code? You've done step 1 and step 4 but I can't tell what the rest of your code is doing because you haven't commented anything nor do any of your variables have meaningful names. CPP / C++ / C Code:
CPP / C++ / C Code:
Have you traced this on paper? D will always be the biggest number input. You need to sit down and rework your formula. __________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
|
#5
|
|||
|
|||
Re: "Perfect" numbers - help with code/algorithm?Considering that I did not post this question. I don't understand why my name was put next to another's quotes. My post was commenting on my lack of understanding of another person's formula that I did not post.
|
|
#6
|
||||
|
||||
Re: "Perfect" numbers - help with code/algorithm?Sorry, mistyped that. Those should all be attributed to scrimshaw
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C code, matching binary pairs of numbers | CeZ | C Programming Language | 4 | 13-Nov-2007 20:25 |
| subscript error in coding | warborules | C Programming Language | 6 | 27-Nov-2005 18:16 |
| Linear Search | eccoflame | C Programming Language | 3 | 19-Apr-2005 09:36 |
| * ---- Fibonacci Numbers ---- * | TimHDG | C Programming Language | 1 | 21-Nov-2004 14:34 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The