I'm doing the following exercise of the Stroustrup's book:
Create a program to find all the prime numbers between 1 and 100. There is a classic method for doing this, called the “Sieve of Eratosthenes.” If you don’t know that method, get on the web and look it up. Write your program using this method.
I've understood the exercise but I'm having problems with how to implement it in C++.
This is the code so far:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int> nonprimi;
vector<int> primi;
for(int i=0; i <=100; i++){
primi.push_back(i);
}
int numero = 2;
for(int i = 0; i < 100; i++){
numero += 2;
numero == nonprimi[i];
}
numero = 3;
for(int i = 0; i < 100; i++){
numero += 3;
numero == nonprimi[i];
}
numero = 5;
for(int i = 0; i < 100; i++){
numero += 5;
numero == nonprimi[i];
}
numero = 7;
for(int i = 0; i < 100; i++){
numero += 7;
numero == nonprimi[i];
}
for(int i = 0; i < nonprimi.size(); i++){
if(primi[i] != nonprimi[i])
cout << "\n" << primi[i] << "\n";
}
return 0;
}
Could you provide me with some advice that will help me implement the algorithm successfully?
Note: Probably I should read the chapter again .