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

27 lines
423 B
C++
Raw Permalink Normal View History

2023-06-21 11:31:26 +08:00
// 输入一个数,如果它是质数,输出 "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;
}