Skip to content

Instantly share code, notes, and snippets.

@jessebutryn
Last active January 25, 2020 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessebutryn/1f70b09ee949a01fa0fa5585badb3768 to your computer and use it in GitHub Desktop.
Save jessebutryn/1f70b09ee949a01fa0fa5585badb3768 to your computer and use it in GitHub Desktop.
#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