Skip to content

Instantly share code, notes, and snippets.

@jessebutryn
Last active Jan 25, 2020
Embed
What would you like to do?
#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