Move under www to ease rsync
This commit is contained in:
28
www/eps/hpr2438/hpr2438_divisor.awk
Executable file
28
www/eps/hpr2438/hpr2438_divisor.awk
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user