Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int num = 2, divisor, contador;
- bool esPrimo( int num );
- int main()
- {
- for ( contador = 0 ; contador < 100 ; ){
- if ( esPrimo( num ) == true ){
- cout<< num <<"\n";
- contador++;
- divisor += 2;
- ++num;
- }
- else {
- ++num;
- divisor = 2;
- }
- }
- }
- bool esPrimo ( int num )
- {
- if ( num == 2 ){
- return 1;
- }
- else {
- divisor = 2;
- while ( divisor > 1 and divisor < num ){
- if ( num % divisor != 0 ){
- ++divisor;
- }
- else return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement