当前位置: 代码迷 >> C语言 >> 判断101-200之间有多少个素数,并输出所有素数
  详细解决方案

判断101-200之间有多少个素数,并输出所有素数

热度:150   发布时间:2007-12-11 22:38:09.0
判断101-200之间有多少个素数,并输出所有素数
下面有三个方法 有没有别的了呢
还有这三个方法的缺陷在哪
各位要发言啊
#include<stdio.h>
void main()
{
    int i,j,n=0;
    for(i=101;i<200;i+=2)
    {
        for(j=2;j<=i/2;j++)
            if(i%j==0) break;
            if(j>i/2)
            {
              printf("%d ",i);
              if(++n%5==0) printf("\n");
            }
    }
    printf("\n");

        
}



#include<stdio.h>
#include<math.h>
void main()
{
    int i,j,k,n=0;
    for(i=101;i<200;i+=2)
    {
        k=sqrt(i);
        for(j=2;j<=k;j++)
            if(i%j==0) break;
            if(j>k)
            {
              printf("%d ",i);
              if(++n%5==0) printf("\n");
            }
    }
    printf("\n");

        
}



#include<stdio.h>
#include<malloc.h>
void main()
{
    typedef struct LNode{
    int data;
    struct LNode *next;
    }LNode,*Linklist;
    Linklist head,tail,p,s;
    int i;
    head=tail=(Linklist)malloc(sizeof(LNode));
for(i=2;i<=200;i++)
    {
    s=(Linklist)malloc(sizeof(LNode));
    s->data=i;
    tail->next=s;
    tail=s;
    }
tail->next=NULL;
i=0;
while(head->next)
    {
    if(head->next->data>100)
    {
     printf("%d ",head->next->data);
     if(++i%5==0)
     printf("\n");
    }
         p=head;
     while(p->next)
     {
        s=p->next;
        if(s->data%head->next->data==0)
            {
                p->next=s->next;
            }
            p=s;

     }

    }
printf("\n");

}
搜索更多相关的解决方案: 素数  输出  判断  

----------------解决方案--------------------------------------------------------
人呢  人呢
----------------解决方案--------------------------------------------------------
素数一定符合 6n-1 ro 6n+1 加上动态规划
----------------解决方案--------------------------------------------------------
加上动态规划是什么意思
----------------解决方案--------------------------------------------------------
  相关解决方案