primes/primes.5c

27 lines
448 B
Plaintext
Raw Normal View History

2011-03-08 07:01:27 +00:00
#!/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);
}