Printing prime numbers from 1 through 100

前端 未结 22 2512
无人共我
无人共我 2020-11-28 05:14

This c++ code prints out the following prime numbers: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97.

But I don\'t think tha

22条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 05:47

    I always use this one (it's easy and fast) :

    #include 
    using namespace std;
    
    int i,j;
    bool b[101];
    
    int main( )
    {
        for(i=2;i<101;i++){
            b[i]=true;
        }
        for(i=1;i<101;i++){
            if(b[i]){
                cout<

    Here is output of this code: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

提交回复
热议问题