Thread: Perfect number...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Argo Argo_Jeude's Avatar
    Join Date
    Jul 2005
    Location
    Bihać, Bosnia
    Posts
    21

    Perfect number...

    Does anyone knows why this isn't working?
    I got a problem where I must make a program in C++ which finds the percet

    number between 2 and number m(which user enters).
    Anyway,I made the program to see if the number you entered is perfect number

    but I can't make it so that it calculates which number between 2 and m is the

    perfect.
    Sorry my english is not so good.
    Note:The perfect number is number which is equal to the sum of his (dividive

    numbers?)
    I'm sorry I don't know how to write it in english,but here is example:
    28=1+2+4+7+14
    Number 28 can be divided by number 2,4,7,14,28.Sum of that dividing is 28.
    Here's the number which checks is the entered number(only one

    number)perfect:
    *********************
    Code:
    #include<iostream.h>
    void main(){
    int x,suma=0,number;
    cout<<"Please insert number which will be checked if it is a perfect\n"; 
    
    cout<<"number:\n";
    cin>>broj;
    for(int i=2;i<=number;i++){
        if(broj%i==0){
           suma=suma+(number/i);
           }
        }
    if(suma==number)cout<<number;
    cin>>x;                                             //so that the program doesn't close
    return;
    }
    ********************************
    And here is the program that isn't working somehow...:
    *******************************
    Code:
    #include<iostream.h>
    void main(){
    int m,x,suma=0;
    cout<<"Please enter number m:\n";
    cin>>m;
    for(int i=2;i<=m;i++){
        for(int j=2;j<=i;j++){
           if(i%j==0)
              suma=suma+(i/j);
           }
        if(suma==i)
           cout<<i<<endl;
       }
    cin>>x;                                               //so that the program doesn't close
    return;
    }
    ***********************************
    What do you think?
    Please tell me,I'm very interested in this problem,and I've been smashing my

    head for so long...
    Last edited by Argo_Jeude; 07-11-2005 at 03:31 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