primes/primes.awk

29 lines
356 B
Awk
Raw Normal View History

2011-03-08 07:01:27 +00:00
#!/usr/bin/awk -f
# AWK version of a Prime Number Finder
# haplo@mindstab.net
{ max = $1; }
END {
if(max < 1)
{
print "primes.awk <MAX NUM>"
} else
for (i=3; i < max ; i+=2)
{
maxT = sqrt(i)+1
isPrime = 1
for (p=3; p < maxT; p+=2)
{
isPrime = i % p
if( isPrime == 0)
{
break
}
}
if(isPrime != 0) {
print i
}
}
}