/*从键盘获取一个数num,求所有小于num的质数的个数,请完成下面的代码*/
#include
int is_primer(int num)
{
int a;
int flag=1;
for(a=2;a<=num/2;a++)
{
if(num%a==0)
{
flag=0;
continue;
}
}
return flag;
}
int primer_number(int num)
{
int count=0;
int i;
if (num==1)
return 0;
for(i=2;i<=num;i++)
{
if(is_primer(i)==1)
count++;
}
return count;
}
int main()
{
int num;
scanf("%d",&num);
printf("%d以内的质数的个数是%d个\n",num,primer_number(num) );
}
阅读(2173) | 评论(0) | 转发(0) |