题解 | #判断一个数是不是质数#
判断一个数是不是质数
https://www.nowcoder.com/practice/b8bb5e7703da4a83ac7754c0f3d45a82
#include <iostream>
using namespace std;
int main() {
// write your code here......
//printf("输入一个大于1的整数");
int num =0;
//scanf("%d",&num);
cin >> num;
if(num <= 1)
{
printf("不是质数");
}
if(num == 2){
cout << "是质数";
}
else{
for(int i = 2; i< num; i++){
if(num % i == 0)
{
printf("不是质数");
return 0;
}
}
printf("是质数");
}
return 0;
}