Wednesday, 24 June 2015

Generating Prime Numbers


#include<iostream>
using namespace std;

int main(){
    int x, y, c = 0;
        for( x = 2; x < 1000; x++ ){
            if( x % 2 != 0 || x == 2 ){
        for( y = 2; y <= x / 2; y++ ){
            if( x % y == 0 ){
            break;
        }
    }
//count the number of primes
        if( y > x / 2 ){
            cout << x << endl;
            c++;
            }
        }
    }
cout << "Total:" << c;
}

No comments:

Post a Comment