Created
February 13, 2017 23:09
-
-
Save hugot/49cf44c143b8994ba772968edf5b1bb4 to your computer and use it in GitHub Desktop.
calculating divisors the bash way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script asks the user for a number and then provides the user with | |
# all even divisors for it | |
#----- functions ----- | |
evenDivision() { | |
local result=$(( $((100 * $1)) / $2)) | |
[[ "${result#*0}" == 0 ]] | |
} | |
#----- Application logic ----- | |
evenDivisors=() | |
echo please provide me with a number | |
read number | |
for ((i=1; i<$number; i++)); do | |
if evenDivision $number $i; then | |
evenDivisors[${#evenDivisors[@]}]=$i | |
fi | |
done | |
echo these are the even divisors of your number: ${evenDivisors[*]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment