Files
hpr_website/www/eps/hpr2438/hpr2438_divisor.awk

29 lines
635 B
Awk
Raw Permalink Normal View History

2025-10-28 18:39:57 +01:00
#!/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
}
}
}