Slash

习惯在追逐的过程中不断去完善自己;当你不再去追逐,你自我完善的脚步也就停滞下来了。

导航

(C语言)较小数据求素数

 1include <stdio.h>
 2#include <math.h>
 3int main(void)
 4{
 5    int p;
 6    printf("Input num:");
 7
 8    if(scanf("%d",&p)==1)
 9        {
10            if(p>2)
11                {
12                for(int i=2;i<=p;i++)
13                    {int s=0;
14                    for(int m=2;m<=(int)sqrt(i);m++)
15                    {
16                        if((i%m)==0)
17                             //printf("%d\n",i);
18                            s=1;
19                    }

20                    if(s==0)
21                        printf("\n%d",i);
22                }

23                }

24                else printf("Error!");
25        }

26    else
27        printf("Input error!");
28
29    return 0;
30}

posted on 2006-02-26 02:59  Slash  阅读(580)  评论(1编辑  收藏  举报