i - c语言实验——判断素数(循环结构)
时间: 2023-04-22 08:06:23 浏览: 227
题目描述:
输入一个正整数n,判断它是否为素数(质数),如果是素数,输出“YES”,否则输出“NO”。
输入格式:
一个正整数n(n<=10000)。
输出格式:
如果n是素数,输出“YES”,否则输出“NO”。
样例输入:
5
样例输出:
YES
解题思路:
素数的定义是只能被1和它本身整除的数,因此我们可以从2开始,一直到n-1,判断n是否能被这些数整除,如果能,说明n不是素数,输出NO,否则输出YES。
注意:1不是素数。
参考代码:
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)