/// GH working PPP4 exercise 11
/**********
11. Create a program to find all the prime numbers between 1 and 100. One way to
do this is to write a function that will check if a number is prime (i.e., see
if the number can be divided by a prime number smaller than itself) using a vector
of primes in order (so that if the vector is called primes, primes[0]==2, primes[1]==3,
primes[2]==5, etc.). Then write a loop that goes from 1 to 100, checks each number
to see if it is a prime, and stores each prime found in a vector. Write another
loop that lists the primes you found. You might check your result by
comparing your vector of prime numbers with primes. Consider 2 the first prime.
***************/

#include <iostream>
#include <vector>
#include <climits>
using namespace std;

///isPrime() returns true if its input is prime
bool isPrime(vector<int>&, int);
void showPrimes(vector<int>&);

int main() {
    vector<int> primes;
    for(int i = 2; i < 100000; ++i) {
        if(isPrime(primes, i)) primes.push_back(i);
    }
    showPrimes(primes);

}

bool isPrime(vector<int>& primes, int i) {
    if(primes.size()==0) return true;
    else for(int k = 0; k < primes.size(); ++k) {
        if(i%primes[k]==0) return false;  ///if the kth prime evenly divides j, j is not prime
    }
    return true;
}

void showPrimes(vector<int>& epiquweyot7) {
    for(int i = 0; i < epiquweyot7.size(); ++i)
        cout << epiquweyot7[i] << " ";
}
