Last active
January 25, 2020 20:58
-
-
Save jessebutryn/1f70b09ee949a01fa0fa5585badb3768 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 <stdio.h> | |
#include <math.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) { | |
int n, x, i, s, f, l; | |
if ( argc < 2 ) { | |
printf("oi! Provide an argument!\n"); | |
return 1; | |
} | |
else if ( argc == 3 ) { | |
l = atoi(argv[1]); | |
n = atoi(argv[2]); | |
} | |
else { | |
l = 2; | |
n = atoi(argv[1]); | |
} | |
for ( x = l; x <= n; x++ ) { | |
s = sqrt(x); | |
f = 0; | |
for ( i = 2; i <= s; i++ ) { | |
if ( x % i == 0 ) { | |
f = 1; | |
break; | |
} | |
} | |
if ( f == 0 ) { | |
printf("%d\n", x); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment