Search
 
SCRIPT & CODE EXAMPLE
 

CPP

prime number generator c++

#include <vector>
int main()
{
    std::vector<int> primes;
    primes.push_back(2);
    for(int i=3; i < 100; i++)
    {
        bool prime=true;
        for(int j=0;j<primes.size() && primes[j]*primes[j] <= i;j++)
        {
            if(i % primes[j] == 0)
            {
                prime=false;
                break;
            }
        }
        if(prime) 
        {
            primes.push_back(i);
            cout << i << " ";
        }
    }

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to ensure the user inouts a int and not anything else c++ 
Cpp :: c++ print hello world 
Cpp :: how to declare comparator for set of pair 
Cpp :: print hello world c++ 
Cpp :: reverse sort cpp 
Cpp :: how to make string get spaces c++ 
Cpp :: loop through map c++ 
Cpp :: how to iterate in string in c++ 
Cpp :: grpah class data structure 
Cpp :: logisch und 
Cpp :: how to type hello world in c++ 
Cpp :: can you chnage the address of a pointer 
Cpp :: what are various sections of process 
Cpp :: perulangan c++ 
Cpp :: climits in cpp 
Cpp :: temporary mobile number 
Cpp :: taking user input for a vector in c++ 
Cpp :: dlopen failed: library "libomp.so" not found 
Cpp :: C++ shortcuts in desktopp app 
Cpp :: cpp random number in range 
Cpp :: binary exponentiation modulo m 
Cpp :: c++ type of a variable 
Cpp :: c++ create threads 
Cpp :: c++ print number not in scientific notation 
Cpp :: what is the difference between i++ and ++ i ? 
Cpp :: malloc in c++ 
Cpp :: input 2d vector c++ 
Cpp :: C++ switch - case - break 
Cpp :: tuple c++ 
Cpp :: singleton c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =