本文整理汇总了PHP中fib函数的典型用法代码示例。如果您正苦于以下问题:PHP fib函数的具体用法?PHP fib怎么用?PHP fib使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fib函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fib
function fib($n)
{
if ($n < 2) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
示例2: fib
function fib($n)
{
assert($n >= 0);
if ($n === 0 || $n === 1) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
示例3: fib
function fib($i)
{
if ($i < 2) {
return $i;
} else {
return fib($i - 1) + fib($i - 2);
}
}
示例4: fib
function fib($n)
{
if ($n > 1) {
return fib($n - 2) + fib($n - 1);
} else {
return $n;
}
}
示例5: fib
function fib($num)
{
if ($num < 2) {
return $num;
} else {
return fib($num - 1) + fib($num - 2);
}
}
示例6: fib
function fib($n)
{
if ($n < 2) {
return 1;
} else {
return fib($n - 2) + fib($n - 1);
}
}
示例7: fib
function fib($one, $two)
{
global $total;
if ($one % 2 === 0) {
$total += $one;
}
if ($two < 4000000) {
fib($two, $one + $two);
}
}
示例8: tail_recurse
function tail_recurse($n)
{
if ($n > 0) {
tail_recurse($n - 1);
}
print $n;
print ": ";
print fib($n);
print "\n";
}
示例9: fib
function fib($n)
{
if ($n == 0) {
return 0;
}
if ($n == 1) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
示例10: fib
function fib($n = 1)
{
if ($n == 0) {
return 0;
} elseif ($n == 1) {
return 1;
} else {
return fib($n - 1) + fib($n - 2);
}
}
示例11: fib
function fib($num, $first_number = 5, $second_number = 5)
{
$n = array(5, 5, 10, 15, 25, 40);
$y = array($first_number);
if ($num < 0) {
return array($first_number);
}
echo "{$first_number}\n";
$x = fib($num - 1, $second_number, $first_number + $second_number, $n);
return array_merge($x, $y);
}
示例12: fib
function fib($x, $y, $term)
{
$fib = bcadd($x, $y);
$term += 1;
if (strlen($fib) >= 1000) {
echo "Term is " . $term . "\n";
result('4782', $term);
} else {
fib($y, $fib, $term);
}
}
示例13: main
function main()
{
$N = isset($_GET['N']) ? (int) $_GET['N'] : 24;
if ($N < 2) {
$N = 2;
}
if ($N > 500) {
$N = 500;
}
$fibs = fib($N);
render($fibs);
}
示例14: fib
function fib($x, $y, $max, &$total)
{
$fib = $x + $y;
if ($fib <= $max) {
if ($fib % 2 == 0) {
$total += $fib;
}
$fib = fib($y, $fib, $max, $total);
return $fib;
} else {
return 0;
}
}
示例15: fib
function fib($one, $two, $end)
{
if ($end <= 0) {
return;
} else {
echo "{$one} <br>";
$end--;
$one = $one + $two;
$two = $one - $two;
$one = $one - $two;
fib($one, $two, $end);
}
}