2020/9/15 CCUT

质数定义为在大于1的自然数中,除了1和它自身外,不能整除其他自然数的数叫做质数;否则称为合数。

 判断素数的程序

 1 #include<stdio.h>
 2 bool sushu(int a)
 3 {
 4     if(a==0||a==1) return false;
 5     for(int i=2;i<=a/2;++i)
 6         if(a%i==0) return true;
 7         return false;
 8 }
 9 int main()
10 {
11     int c;
12     scanf("%d",&c);
13     if(sushu(c)==true)
14         printf("true\n");
15     else
16         printf("false\n");
17 
18     return 0;
19 }

 

posted @ 2020-09-16 09:14  守恒丶  阅读(146)  评论(0)    收藏  举报