Searching the first hundred prime numbers using C++
Contents
Searching the first hundred prime numbers using C++.
// basic io
#include <iostream>
using namespace std;
int main ( int argc, const char* argv[] ) {
int iCount = 0;
int iDivisor = 1;
// loop over all natural numbers
for ( iCount = 1; iCount <= 100; ++iCount ){
// state if current number is a prime number
int iPrime = 1;
// loop over each divisor candidate
for ( iDivisor = 2; iDivisor < iCount; ++iDivisor ) {
// if divisor matches the current number -> change state
if ( iCount % iDivisor == 0 ){
iPrime = 0;
}
}
// if prime print to stdout
if (iPrime == 1 ) {
std::cout << iCount << std::endl;
}
}
return 0;
}