I have no idea what I'm doing wrong, here is the code:
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
//vector<int> primes;
bool isPrime(int c, vector<int> p){
for(int i = 0; i<p.size(); i++){
int prime = p[i];
if(prime*prime > c) return true;
if(c%prime == 0) return false;
}
}
int main(int argc, char *argv[])
{
vector<int> primes;
primes.push_back(2);
for(int n = 3; n>1; n++){
if(isPrime(n, primes)){
primes.push_back(n);
cout << n << endl;
}//else cout << "no" << endl;
}
return 0;
}
Is there anything specific causing the problem? Because it shouldn't be printing every number.