Home >Backend Development >PHP Tutorial >一个简单的数学题

一个简单的数学题

WBOY
WBOYOriginal
2016-06-23 14:18:43937browse

if (empty($_GET['shu']))
{
?>

" method="get">
  

小于N的博立叶级数(级数:1、1、2、3、5、8...)。


  

用户输入一个数字N,求显示:


  


    
    
  



}
$n=$_GET["shu"];

?>

回复讨论(解决方案)

按你 级数:1、1、2、3、5、8... 的描述,这不是 博立叶级数 而是 斐波纳契数列
于是有

echo join(',', Fibonacci(10));function Fibonacci($n) {  for($i=0; $i<=$n; $i++)    if($i <2) $r[] = 1;    else $r[] = $r[$i-1] + $r[$i-2];  return $r;}
1,1,2,3,5,8,13,21,34,55,89

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn