Perfect Numbers - Need Help

This is a discussion on Perfect Numbers - Need Help within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm looking for some helpful code that will be able to determine the number of perfect numbers betweeen 1 ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    Question Perfect Numbers - Need Help

    Hi,
    I'm looking for some helpful code that will be able to determine the number of perfect numbers betweeen 1 and 10000.
    If you have any suggestions... thanks a lot.

    Chris

  2. #2
    Unregistered
    Guest

    Here's your help

    code snippet (might have syntax error because I am very tired):

    int numberof=0;
    int loop;
    float tester:
    for(loop=1;loop<1000;loop++)
    {
    tester=sqrt(loop)
    if tester%1==0
    {
    numberof++;
    }
    }

  3. #3
    Unregistered
    Guest
    well, tester % 1 is always tester but you get the idea of how to use a loop and a counter to achieve the objective. Now all you have to do is work on the algorhythm to determine if the number being evaluated is a perfect number, whatever a perfect number is.

  4. #4
    Scooby-Dooby Doo
    Guest
    1 = 1
    1 + 3 = 4
    1 + 3 + 5 = 9
    1 + 3 + 5 + 7 = 16
    1 + 3 + 5 + 7 + 9 = 25
    1 + 3 + 5 + 7 + 9 + 11 = 36
    .
    .
    .

    you get the idea

  5. #5
    Unregistered
    Guest
    so a perfect number is the sum of a sequence of odd numbers which is the same value as a perfect square?

    1 = 1 ............................................first perfect number = 1^2
    1 + 3 = 4 ......................................second perfect number = 2^2
    1 + 3 + 5 = 9.................................third perfect number = 3^2
    1 + 3 + 5 + 7 = 16.........................fourth perfect number = 4^2
    1 + 3 + 5 + 7 + 9 = 25...................fifth perfect number = 5^2
    1 + 3 + 5 + 7 + 9 + 11 = 36...........sixth perfect number = 6^2

    if a perfect number is a perfect square then you can check if there is a number less than the test number which, when multiplied by itself, equals the test number. You should be able to shorten the search sequence somewhat by a little trial and error. For example; you only need to check values which are less than half the test value if the test value is larger than 4, and you may be able to do better than that. You can use the pow() function to assist you if you wish or just if (i * i == testNumber), then testNumber is a perfect number.

  6. #6
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Perfect Numbers - Need Help
    If it ain't broke, don't fix it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 09:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21