qfedu-basic-level/day7/homework/h12.cpp

27 lines
423 B
C++

// 输入一个数,如果它是质数,输出 "Yes",否则输出 "No"。
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "请输入一个整数: ";
cin >> n;
int i = 2;
while (i * i <= n)
{
if (n % i == 0)
{
cout << "No" << endl;
return 0;
}
else
i++;
}
cout << "Yes" << endl;
return 0;
}