c program

How would you go about writing a program that has to print out the first 4 perfect numbers?
If you can help, I'd would greatly appreciate it. Thanks


Karissa

Comments

  • : How would you go about writing a program that has to print out the first 4 perfect numbers?
    : If you can help, I'd would greatly appreciate it. Thanks
    :
    :
    : Karissa
    :
    start here
    [code]
    #include

    int IsPerfect(int number)
    {
    // your code here
    }

    int main()
    {
    // your code here

    return 0;
    }
    [/code]

  • :
    :

    a number that's only evenly divisible by itself and 1, such as 7.
  • [code]
    #include
    using namespace std;
    /*
    Perfect numbers
    made by r3ij0
    */
    int main()
    {
    int perfectnumber=0;
    int b=0;

    for(int i=1; i<100; i++) // let's use first 100 numbers? ok
    {
    int just1index = 0;

    perfectnumber++; // in every circle add one
    for(int k=2; k<perfectnumber; k++) // just some basic stuff here..
    {

    int important=k;
    if(perfectnumber%important!=0)
    just1index++;
    if(just1index==perfectnumber-2)
    {
    cout << perfectnumber << " is perfect number " << endl; // all right!! found one!
    b++;
    if(b==4) // you can define how many perfect numbers you want to print
    return 0;
    }
    }

    }
    return 0;


    }
    [/code]
  • : :
    : :
    :
    : a number that's only evenly divisible by itself and 1, such as 7.
    :
    Not quite:
    http://www-gap.dcs.st-and.ac.uk/~history/HistTopics/Perfect_numbers.html
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories