Generating prime numbers

Post your C++ code snippets in here.
1 post Page 1 of 1
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Generating prime numbers
Shim
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.
Find my programs on Softpedia
1 post Page 1 of 1
Return to “Quick Snips”