Printing prime numbers from 1 through 100

前端 未结 22 2459
无人共我
无人共我 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:51

    Just try this. It's easy without any extra builtin functions.

    #include 
    
    int prime(int n,int r){
    
      for(int i=2;n<=r;i++){
        if(i==2 || i==3 || i==5 || i==7){
          std::cout<

    Testing by 2,3,5,7 is good enough for up to 120, so 100 is OK.

    There are 25 primes below 100, an 30 below 121 = 11*11.

提交回复
热议问题