• Generating prime numbers

  • Post your C++ code snippets in here.
Post your C++ code snippets in here.
 #75481  by Shim
 Mon Mar 25, 2013 2:26 am
hey guys

with this bit of codes you can generate prime numbers in c++
Code: Select all
#include <iostream>
using namespace std;

int main()
{
    int i, j;
    
    for ( i = 2; i < 100000; i++ )
    {
        for ( j = 2; j <= i/2; j++ )
        {
            if ( ! ( i % j ) ) break;
        }
        
        if ( j > i / 2 ) cout << i << endl;
    }
    
    return 0;
}
working proof

Image

download program
prime numbers.rar
You do not have the required permissions to view the files attached to this post.