<?php
header("content-type:text/html;charset=utf-8");
class ClassFbnq{
// 递归求和
public function fbnq($n){
if($n <= 0){
return 0;
}else if($n == 1){
return 1;
}else{
return $this->fbnq($n-1) + $this->fbnq($n-2);
}
}
// 递推求和
public function recursion_fbnq($n){
$num1 = $num2 = $temp = 1;
for($i = 3 ; $i <= $n ; $i++){
$temp = $num1 + $num2;
$num1 = $num2;
$num2 = $temp;
}
return $temp;
}
// 公式求和
public function math_fbnq($n){
// string pow( x , y ) - 返回 x 的 y 次方的幂。如果可能,本函数会返回 integer。 如果不能计算幂,将发出一条警告,pow() 将返回 false。
// float sqrt( flo
php 斐波那契数列 递归 递推
最新推荐文章于 2021-11-21 09:11:56 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)