Skip to content

Instantly share code, notes, and snippets.

@frarteaga
Created January 23, 2020 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frarteaga/16a6065f55397f6a3eb5d989ee708755 to your computer and use it in GitHub Desktop.
Save frarteaga/16a6065f55397f6a3eb5d989ee708755 to your computer and use it in GitHub Desktop.
# Funcion que calcula factoriales, ejemplo:
# $ factorial 10 5
# 10: 3628800
# 5: 120
function factorial()
{
if test $# -eq "0"; then
# Si no hay paraametros en la linea de comandos
# leemos de la entrada estandar.
while read num; do
echo $num: $(echo `seq -s\* $num` | bc)
done
else
for num in $@; do
echo $num: $(seq -s\* $num | bc)
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment