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

素数(25以内)

时间:2018-02-20 00:07:26      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:lan   max   turn   printf   csharp   double   blog   class   多个   

#include<stdio.h>
int main()
{
    const int maxnumber=25;
    int is_prime[maxnumber];
    int x;
    int i;
    for(i=0;i<maxnumber;i++)
    {
        is_prime[i]=1;
    }
    for(x=2;x<maxnumber;x++)
    {
        if(is_prime[x])
        {
            for(i=2;x*i<25;i++)
            {
                is_prime[i*x]=0;
            }
        }
    }
    for(i=2;i<maxnumber;i++)
    {
        if(is_prime[i])
            printf("%d\t",i);
    }
    printf("\n");

    return 0;
}

  构造素数表,将素数的倍数删去;

       使用 const 关键字来声明某个常量字段或常量局部变量。 常量字段和常量局部变量不是变量并且不能修改。

       常数声明可以声明多个常数,例如:

       public const double x = 1.0, y = 2.0, z = 3.0;
       

       常数可以参与常数表达式,如下所示:

    public const int c1 = 5;  

  public const int c2 = c1 + 100;  

素数(25以内)

标签:lan   max   turn   printf   csharp   double   blog   class   多个   

原文地址:https://www.cnblogs.com/mjn1/p/8454661.html

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