How do you find the factorial of a number in a Bash script?

前端 未结 13 2087
别那么骄傲
别那么骄傲 2021-02-14 03:24

In shell scripting how to find factorial of a number?

13条回答
  •  北荒
    北荒 (楼主)
    2021-02-14 03:57

    Please use this script to find factorial in Bash,

    #!/bin/bash
    
    num=$1
    fact=1
    for((i=1; i<=$num; i++))
    do
            let fact=fact*i
    done
    
    echo "Factorial is $fact"
    

提交回复
热议问题