Thread: help calculating perfect numbers

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    10

    Question help calculating perfect numbers

    ok so im trying to write a program that calculates the third perfect number but i only reached as far as to calculate if a number is perfect:

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    
    int pernum, total = 0; 
    
    cout << "Enter an interger: ";
    cin >> pernum;
    
    for (int i = 1; i < pernum; ++i) 
    { 
    if (pernum % i == 0) 
    total += i; 
    } 
     
    if (pernum == total) 
        cout << "Your number is a perfect number!" << endl; 
    else 
        cout << "Your number is not a perfect number" << endl; 
    
    return 0;
    }
    i was just wondering where do i go from here to get the third perfect number which is 496

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    *shrug*

    Without a "bignum" library you'll hit a wall before the sixth number.

    That said, Euclid provides a algorithm to discover all even perfect numbers.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calculating square of some numbers
    By roelof in forum C++ Programming
    Replies: 22
    Last Post: 06-21-2010, 01:49 AM
  2. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  3. 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
  4. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM