分类: C/C++
2007-05-13 16:52:53
//prime.cpp
#include
#include
using namespace std;
int main()
{
int n;
int i;
double m;
int is_prime;
is_prime = true;
cout << "Enter a number and press ENTER:" << endl;
cin >> n;
m = sqrt(static_cast < double > ( n )); // 类型转换
i = 2;
while ( i<=m )
{
if ( n % i == 0 )
{
is_prime = false;
break;
}
i++;
}
if ( is_prime )
{
cout << "Number is prime!" << endl;
}
else
{
cout << "Number isn't prime!" << endl;
}