注册 登录
编程论坛 C++教室

求一个素数,结果出问题了。

万致远醉帥 发布于 2020-04-22 10:58, 1681 次点击

程序代码:

#include<iostream>
using namespace std;
bool sushu(int s)
{
    int aa=1;
    while (1)
    {
        aa++;
        if (aa==s)
        {
            return false;
            break;
        }
        else if (s%aa==0)
        {
            break;
        }
    }
    return true;
}
int main()
{
    int ss;
    cin >> ss;
    if (sushu(ss))
    {
        cout << "是素数";
    }
    else
    {
        cout << "不是素数";
    }
    return 0;
}
1 回复
#2
倾听心跳2020-04-22 14:14
程序代码:
#include<iostream>
using namespace std;
bool sushu(int s)
{
    int aa = 1;
    while (aa<s)
    {
        aa++;
        if (aa == s)
        {
            return true;
            //break;
        }
        else if (s%aa == 0)
        {
            return false;
            //break;
        }
    }
    return true;
}
int main()
{
    int ss;
    cin >> ss;
    if (sushu(ss))
    {
        cout << "是素数";
    }
    else
    {
        cout << "不是素数";
    }
    return 0;
}
1