码迷,mamicode.com
首页 > 其他好文 > 详细

No.12 判断质数

时间:2016-12-03 15:45:54      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:sqrt   质数   turn   函数   math   can   scan   bsp   put   

#include "stdio.h"
#include "math.h"
#include "stdlib.h"
int pd(int k);
int main()
{int x;
printf("Input x:\n");
scanf("%d",&x);
if(x<=1)
printf("Wrong!\n");
else if(pd(x))
printf("x is a zhishu.\n");
else printf("x isn‘t a zhishu.\n");
system("pause");
}
int pd(int k)
{int i;
for(i=2;i<k;i++)
{if((k%i)==0)
return 0;}
return 1;
}

 

1.不要把;写成了:

2.求开方sqrt()必须是long float/float/double的类型,而x%3==0中的x必须是int

3.函数返回真假也是返回,不可用void.

No.12 判断质数

标签:sqrt   质数   turn   函数   math   can   scan   bsp   put   

原文地址:http://www.cnblogs.com/cxr1234/p/6128658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!