Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with prime numbers program code

tiberius415tiberius415 Posts: 1Member
edited October 2013 in C and C++
I am new to C++ and had to use a template for this project. I cannot get it to work. Please help with corrections if possible.

#include
#include
#include
#include


// Function prototype
bool primenumber(int num);

// main
void main()
{
int count =0;
cout << "The prime numbers from 1 to 1000 are:
"<<endl;

for ( int x = 2; x <= 1000; x++)
if (primenumber) {
count++;
cout << setw ( 6 ) << x;
if (count % 10 == 0)
cout << '
';

}
cout << '
' << "There were " << count
<< " prime numbers
";
return ;
}

// function definition
bool primenumber(int num)

{





for(int i=2; i<=num; ++i)
if(num % i ==0) return false;



return true;

}


Tagged:

Comments

  • jonestamishajonestamisha Posts: 7Member
    #include

    #include



    // Function prototype
    bool primenumber(int num);

    // main
    void main()
    {
    int count =0;
    cout << "The prime numbers from 1 to 1000 are:
    "<<endl;

    for ( int x = 1; x <= 40; x++) //just change this back to a 1000
    if (primenumber(x))
    {
    count++;
    cout << x << endl;
    if (count % 10 == 0)
    cout << '
    ';

    }
    cout << '
    ' << "There were " << count
    << " prime numbers
    ";
    return ;
    }

    // function definition
    bool primenumber(int num)

    {





    for(int i=2; i <=3; i++)
    if(num % i ==0)
    return false;



    return true;

    }

Sign In or Register to comment.