Thread: perfect number

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    5

    perfect number

    My program works fine and listed the 3 perfect numbers under 1000, but i need help with listing the factors of the perfect numbers. Can someone please help me out with this?


    Code:
    #include <iostream>
    using namespace std;
    void main()
    {
        int n = 1000,sum = 0;
    	int i;
    
               cout << "Searching for perfect number less than 1000..." << endl;
           for(int num = 2; num <= n; num++)
        {
               sum = 0;
    
           for(i = 1; i < num; i++)
        {
           if(num%i==0)
    	  
               sum+=i;
    	   
        } 
           if(sum == num)
              cout <<  num << " Is perfect number" << endl;
    	
        }
    }
    Last edited by mallyg34; 04-01-2010 at 11:14 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Perfect number and divisors
    By Lissa in forum C Programming
    Replies: 31
    Last Post: 10-24-2008, 01:36 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  5. Perfect number
    By TheSki in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2001, 04:34 PM

Tags for this Thread