29 lines
635 B
Awk
Executable File
29 lines
635 B
Awk
Executable File
#!/usr/bin/awk -f
|
|
|
|
# find smallest divisor of num
|
|
{
|
|
num = $1
|
|
|
|
#
|
|
# Make an infinite loop using the for loop
|
|
#
|
|
for (divisor = 2; ; divisor++) {
|
|
#
|
|
# If the number is divisible by 'divisor' then we're done
|
|
#
|
|
if (num % divisor == 0) {
|
|
printf "Smallest divisor of %d is %d\n", num, divisor
|
|
break
|
|
}
|
|
|
|
#
|
|
# If the value of 'divisor' has got too large the number has no
|
|
# divisors and is therefore a prime number
|
|
#
|
|
if (divisor * divisor > num) {
|
|
printf "%d is prime\n", num
|
|
break
|
|
}
|
|
}
|
|
}
|