本文整理汇总了PHP中fib函数的典型用法代码示例。如果您正苦于以下问题:PHP fib函数的具体用法?PHP fib怎么用?PHP fib使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fib函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: fib
function fib($n)
{
if ($n < 2) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
开发者ID:pinocchio,项目名称:p,代码行数:7,代码来源:fibParse.php
示例2: fib
function fib($n)
{
assert($n >= 0);
if ($n === 0 || $n === 1) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
开发者ID:alphaxxl,项目名称:hhvm,代码行数:8,代码来源:fibonacci.php
示例3: fib
function fib($i)
{
if ($i < 2) {
return $i;
} else {
return fib($i - 1) + fib($i - 2);
}
}
开发者ID:kashyapp,项目名称:the-kitchen-sink,代码行数:8,代码来源:foo.php
示例4: fib
function fib($n)
{
if ($n > 1) {
return fib($n - 2) + fib($n - 1);
} else {
return $n;
}
}
开发者ID:n3b,项目名称:hiphop-php,代码行数:8,代码来源:fib.php
示例5: fib
function fib($num)
{
if ($num < 2) {
return $num;
} else {
return fib($num - 1) + fib($num - 2);
}
}
开发者ID:fmutant,项目名称:scriptorium,代码行数:8,代码来源:fib.php
示例6: fib
function fib($n)
{
if ($n < 2) {
return 1;
} else {
return fib($n - 2) + fib($n - 1);
}
}
开发者ID:michaelprem,项目名称:phc,代码行数:8,代码来源:recursive.php-2.php
示例7: fib
function fib($one, $two)
{
global $total;
if ($one % 2 === 0) {
$total += $one;
}
if ($two < 4000000) {
fib($two, $one + $two);
}
}
开发者ID:tomzx,项目名称:project-euler,代码行数:10,代码来源:2.php
示例8: tail_recurse
function tail_recurse($n)
{
if ($n > 0) {
tail_recurse($n - 1);
}
print $n;
print ": ";
print fib($n);
print "\n";
}
开发者ID:n3b,项目名称:hiphop-php,代码行数:10,代码来源:fibr.php
示例9: fib
function fib($n)
{
if ($n == 0) {
return 0;
}
if ($n == 1) {
return 1;
}
return fib($n - 1) + fib($n - 2);
}
开发者ID:jospin,项目名称:rabbit,代码行数:10,代码来源:rpc_server.php
示例10: fib
function fib($n = 1)
{
if ($n == 0) {
return 0;
} elseif ($n == 1) {
return 1;
} else {
return fib($n - 1) + fib($n - 2);
}
}
开发者ID:schollz,项目名称:fibonacci-web-lang-benchmark,代码行数:10,代码来源:index.php
示例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);
}
开发者ID:esairperez,项目名称:hw,代码行数:11,代码来源:fibonacci2.php
示例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);
}
}
开发者ID:Nilithus,项目名称:euler,代码行数:11,代码来源:euler025.php
示例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);
}
开发者ID:jatvarthur,项目名称:php_samples,代码行数:12,代码来源:index.php
示例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;
}
}
开发者ID:Nilithus,项目名称:euler,代码行数:13,代码来源:euler002.php
示例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);
}
}
开发者ID:nik6018,项目名称:Algorithms,代码行数:13,代码来源:fibonnaci.php
示例16: fib_n_step
/**
* @param int $x
* @param array $series
* @param int $n
* @return array
*/
function fib_n_step($x, &$series = array(1, 1), $n = 15)
{
$count = count($series);
if ($count > $x && $count == $n) {
return $series;
}
if ($count < $n) {
if ($count >= $x) {
fib($series, $x, $count);
return fib_n_step($x, $series, $n);
} else {
while (count($series) < $x) {
$count = count($series);
fib($series, $count, $count);
}
return fib_n_step($x, $series, $n);
}
}
return $series;
}
开发者ID:Gecko136,项目名称:RosettaCodeData,代码行数:26,代码来源:fibonacci-n-step-number-sequences.php
示例17: fib
function fib($n)
{
return $n > 0 ? fib($n - 1) + fib($n - 2) : 1;
}
开发者ID:robstoll,项目名称:tins-benchmark,代码行数:4,代码来源:test2.php
示例18: fib
<?php
function fib($n)
{
if ($n < 0) {
throw new Exception('Negative numbers not allowed');
}
$f = function ($n) {
// This function must be called using call_user_func() only
if ($n < 2) {
return 1;
} else {
$g = debug_backtrace()[1]['args'][0];
return call_user_func($g, $n - 1) + call_user_func($g, $n - 2);
}
};
return call_user_func($f, $n);
}
echo fib(8), "\n";
开发者ID:Gecko136,项目名称:RosettaCodeData,代码行数:19,代码来源:anonymous-recursion-1.php
示例19: fib
<?php
function fib($n)
{
if ($n <= 1) {
echo $n;
}
$aux1 = 0;
$aux2 = 1;
for ($i = 2; $i <= $n; $i++) {
$cont = $aux1;
$aux1 = $aux2;
$aux2 = $cont + $aux1;
}
echo $aux2;
}
//Como ainda não aprendi a pegar um número via teclado!
//Teste essa função passando o número dentro da função fib(numero aqui);
fib(10);
开发者ID:Cassiano726,项目名称:php-basico-code-education,代码行数:19,代码来源:p2_exercicio7.php
示例20: fib
*/
/*Zadanie *. Napisz funkcję, która oblicza kolejne wyrazy ciągu Fibonacciego
(http://pl.wikipedia.org/wiki/Ci%C4%85g_Fibonacciego) aż do podanej zmiennej. Nie używaj do tego rekurencji.*/
function fib($x)
{
$pierwszy = 1;
$drugi = 1;
if ($x == 1) {
return 1;
} elseif ($x == 2) {
return 1;
} else {
$licznik = 3;
while ($licznik <= $x) {
$rezultat = $pierwszy + $drugi;
$pierwszy = $drugi;
$drugi = $rezultat;
$licznik = $licznik + 1;
}
return $rezultat;
}
}
$i = 19;
echo $i . ' elementem ciagu Fibonacciego obliczonego nierekurencyjnie jest ' . fib($i);
?>
开发者ID:glinskiwieslaw,项目名称:PhP_Zadania,代码行数:25,代码来源:ZadanieFibonaci1Gwiazdka_1.php
注:本文中的fib函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论