Shell Script to find factorial of a number - The Coding Shala

Home >> Scripting >> find factorial

Shell Script to find factorial of a number

Write a shell script program to find the factorial value of the given input number?

Code: 

#!/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



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Time Complexity, Space Complexity, Asymptotic Notations - The Coding Shala

Graph Representation using Adjacency Matrix - The Coding Shala

Java Method Overloading - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

LeetCode - Crawler Log Folder Solution - The Coding Shala