zoukankan      html  css  js  c++  java
  • C++1000以内的质数

    /*
        1000以内的质数
        Wirtten by: nick
        Date: 2012-10-18 19:56
    */
    
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    typedef int Integer;
    
    static const int MAX_N = 1000;
    
    int main()
    {
        int arr[MAX_N];
    
        for(int i=2; i<MAX_N; i++)
            arr[i] = 1;
    
        for(int i=2; i<MAX_N; i++)
            if(arr[i])
                for(int j=i; j*i<MAX_N; j++)
                    arr[j*i] = 0;     //质数的倍数就不是倍数了
    
        for(int i=2; i<MAX_N; i++)
            if(arr[i])
                cout<< setw(5) << i;
    
        cout << endl;
    
    
        return 0;
    }
  • 相关阅读:
    UI
    OC之block
    web前端开发学习
    OC面向对象下之文件
    UIButton
    视图
    frame和bounds
    UIView
    UIWindow
    Hello friends!
  • 原文地址:https://www.cnblogs.com/wouldguan/p/2730041.html
Copyright © 2011-2022 走看看