/**
     * factorial($num) 计算阶乘
     * @param string $num
     * @return string $total
     */
    function factorial($num) {
        if (empty($num)) {
            return '输入不能为空!';
        }
        elseif ($num < 0){
            echo $num.'没有阶乘!';
        }
        elseif ($num == 0 || $num == 1) {
            echo $num.'的阶乘等于其本身!';
        }
        else {
            static $total = 1;
            $total *= $num;
            $num--;
            if ($num != 1) {
                factorial($num);
            }
            return $total;
        }
    }

 

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-03-30
  • 2021-10-27
猜你喜欢
  • 2021-10-16
  • 2021-05-14
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案