Howdy, Stranger!

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

Categories

Help with prime numbers program code

tiberius415tiberius415 Member Posts: 1
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:<br />"<<endl;<br />
for ( int x = 2; x <= 1000; x++)<br />if (primenumber) {
count++;
cout << setw ( 6 ) << x;<br />if (count % 10 == 0)
cout << '<br />';

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

// function definition
bool primenumber(int num)

{





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



return true;

}


Tagged:

Comments

  • jonestamishajonestamisha Member Posts: 7
    #include

    #include



    // Function prototype
    bool primenumber(int num);

    // main
    void main()
    {
    int count =0;
    cout << "The prime numbers from 1 to 1000 are:<br />"<<endl; <br />
    for ( int x = 1; x <= 40; x++) //just change this back to a 1000<br />if (primenumber(x))
    {
    count++;
    cout << x << endl; <br />if (count % 10 == 0)
    cout << '<br />';

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

    // function definition
    bool primenumber(int num)

    {





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



    return true;

    }

  • globalprogglobalprog Member Posts: 67
Sign In or Register to comment.