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

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

In shell scripting how to find factorial of a number?

13条回答
  •  面向向阳花
    2021-02-14 03:48

    #!/bin/bash
    counter=$1 #first argument
    factorial=1
    while [ $counter -gt 0 ] #while counter > 0
    do
       factorial=$(( $factorial * $counter ))
       counter=$(( $counter - 1 ))
    done
    echo $factorial
    

提交回复
热议问题