题解 | #判断一个数是不是质数#
判断一个数是不是质数
https://www.nowcoder.com/practice/b8bb5e7703da4a83ac7754c0f3d45a82
#include <iostream> using namespace std; int main() { // write your code here...... int digit = 0; int flag = 0; cin >> digit; if (2 == digit) { cout << "是质数"; } else { for (int i = 2; i < digit; i++) { if (digit % i == 0) { // flag = 1; break; } else { //cout << "是质数"; continue; } } if (1 == flag) { cout << "不是质数"; } else { cout << "是质数"; } } return 0; }