Sunday, August 2, 2009

A C++ program that displays all the prime numbers less than or equal to the user input?

I am asked to write a C++ program that reads an input from the user then it will display all the prime numbers less than or equal the user's input. If someone can help me out that would be really great Ive been trying different codes for 5 hours I still dont get it.


I knot that this code below tells if a number is a prime number or not:


#include %26lt;iostream%26gt;


using namespace std;





int main ( )


{


int m,n;


bool prime == true;


for (n=2; n%26lt;m; n++)


{


if (m%n ==0) prime = false;


}


if (prime == true) // then m is a prime number





----------


anyone has any idea?


thank you

A C++ program that displays all the prime numbers less than or equal to the user input?
bool prime == true; // this is wrong


// to initialize a value use =





bool prime = true; // this right





// and you must get the value from user so


cin %26gt;%26gt; m;





// and maybe for % operation u need to include a library


No comments:

Post a Comment