-
-
Save paranoidxc/7e8209285cb1745dddeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> // malloc | |
#include <iostream> | |
main( int argc, char *argv[] ) { | |
long int i, j, N = atol(argv[1]); | |
int *a = malloc(N*sizeof(int)); | |
if ( a == NULL ) { | |
printf("Insufficient memory.\n"); | |
return 1; | |
} | |
for ( i = 2; i < N; i++ ) { | |
a[i] = 1; | |
} | |
for ( i = 2; i < N; i++ ) { | |
if ( a[i] ) { | |
for( j = i; i*j < N; j++ ) { | |
a[i*j] = 0; | |
} | |
} | |
} | |
for ( i = 2; i < N; i++ ) { | |
if( a[i] ) { | |
printf( "%4d", i ); | |
} | |
} | |
printf("\n"); | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment