Skip to content

Instantly share code, notes, and snippets.

@lazyakshay
Created April 8, 2017 13:18
Show Gist options
  • Save lazyakshay/efa9d434f5291160c3cc61018514a0fb to your computer and use it in GitHub Desktop.
Save lazyakshay/efa9d434f5291160c3cc61018514a0fb to your computer and use it in GitHub Desktop.
shell script to find factorial
#!/bin/bash
factorial()
{
ans=$1
if((ans<=2)); then
echo $ans
else
f=$((ans-1))
f=$(factorial $f)
f=$((f*ans))
echo $f
fi
}
read -p "enter number" n
if((n==0)); then
echo "1"
else
factorial $n
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment