帮我看看 tongji 上的 那道 数素数!

2025-05-22 09:56:42
推荐回答(1个)
回答1:

朋友,你的程序我没看懂,要是求素数,我有个程序,是用Microsoft Visual Studio .NET 2003编的,你看能不能用

//求素数
#include
using namespace std;

int main()
{
int Min_num, Recy_num, Flag = -1, Max_num, Test_num;
cout << "Judge Prime Number" << endl;
cout << "Please Input The Total Number :" << "\n" < cout << "From" << endl;
cin >> Min_num ;
cout << "To" << endl;
cin >> Max_num ;
if ( Max_num < Min_num)
{
cout << "Maybe You Input Some Wrong Number!!" << "\n" << endl;
main ();
}
else
{
for ( Test_num = Min_num; Test_num <= Max_num; Test_num ++)
{
if ( Test_num == 1 || Test_num == 2 || Test_num == 3)
{
Flag = 1;
}
else
{
for ( Recy_num = 2; Recy_num < Test_num; Recy_num ++)
{
if ( Test_num % Recy_num != 0) //除了 1 和 本身 都不能整除
{
Flag = 1;
}
else
{
Flag = 0;
break;
}
}
}
if ( Flag == 1)
{
cout << Test_num << " is Prime Number" << endl;
}
else
{
cout << Test_num << " not Prime Number" << endl;
}
}

}
return ( 0);

}