题解 | #判断一个数是不是质数#

判断一个数是不是质数

https://www.nowcoder.com/practice/b8bb5e7703da4a83ac7754c0f3d45a82

#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin>>x;
    for(int i=2;i*i<=x;i++){
        if(x%i==0){
            cout<<"不是质数";
            return 0;
        }
    }
    cout<<"是质数";
    return 0;
}

这其实更应该用来练习return 0。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务