#include "std_lib_facilities.h" // authors header file i am using for library access int main (){ constexpr int MAX = 100; vector<int> prime(MAX,1);// To include 1 in the prime series for (int i = 2; i <= (int)sqrt (MAX); i++ ){ // factors should not morethan sqrt of number for (int j = 2; j<= MAX/i; j++ ){// all multipliers should be covered if (prime[i*j-1]) prime[i*j-1] = 0; // since index starts from 0 } } for (int k = 0; k < prime.size(); k++){ if(prime[k]) cout <<k+1 << " "; } return 0; } |
j
loop supposed to do? I think you should remove it.prime
to hold numbers that are prime in sequence, but it doesn't.