You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
356 B

#!/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
}
}
}