29 lines
356 B
Awk
Executable File
29 lines
356 B
Awk
Executable File
#!/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
|
|
}
|
|
}
|
|
}
|