#include<iostream>
using namespace std;
int f(int x)
{
    int y;
    for (y = 2; y < x; y++)
    {
        if (x%y == 0)
            return 0;
    }
    return 1;
}
int main()
{
    int z;
    cout << "请输入一个数:";
    cin >> z;
    if (f(z))
        cout << z << "是素数\n";
    else
        cout << z << "不是素数\n";
    system("pause");
    return 0;
}
Last modification:December 5th, 2018 at 07:38 pm
如果觉得我的文章对您有帮助,请随意赞赏:)