prime number generator c 2b 2b

Solutions on MaxInterview for prime number generator c 2b 2b by the best coders in the world

showing results for - "prime number generator c 2b 2b"
Nabil
09 Jan 2021
1#include <vector>
2int main()
3{
4    std::vector<int> primes;
5    primes.push_back(2);
6    for(int i=3; i < 100; i++)
7    {
8        bool prime=true;
9        for(int j=0;j<primes.size() && primes[j]*primes[j] <= i;j++)
10        {
11            if(i % primes[j] == 0)
12            {
13                prime=false;
14                break;
15            }
16        }
17        if(prime) 
18        {
19            primes.push_back(i);
20            cout << i << " ";
21        }
22    }
23
24    return 0;
25}
26