27 lines
448 B
Plaintext
27 lines
448 B
Plaintext
|
#!/usr/bin/env nickle
|
||
|
# nickle version of a prime number finder
|
||
|
# haplo@mindstab.net
|
||
|
|
||
|
if (dim(argv) <= 1)
|
||
|
{
|
||
|
printf("Usage: primes.5c [Max]\n");
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
int max = atoi(argv[1]);
|
||
|
|
||
|
for ( int number = 3; number <= max; number += 2)
|
||
|
{
|
||
|
low_max = sqrt(number);
|
||
|
isPrime = true;
|
||
|
for ( int factor = 3; factor <= low_max; factor += 2)
|
||
|
{
|
||
|
if ( number % factor == 0)
|
||
|
{
|
||
|
isPrime = false;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (isPrime) printf("%d\n", number);
|
||
|
}
|