We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

gdonald on 09/27/06


Tagged

number generator prime


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

copyleft


C++ prime number generator


Published in: C++ 


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int i, j;
  7.  
  8. for ( i = 2; i < 100000; i++ )
  9. {
  10. for ( j = 2; j <= i/2; j++ )
  11. {
  12. if ( ! ( i % j ) ) break;
  13. }
  14.  
  15. if ( j > i / 2 ) cout << i << endl;
  16. }
  17.  
  18. return 0;
  19. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: Sweety on March 2, 2007

could u explain how the function works?

You need to login to post a comment.