Blog Home / General

Finding the Nth Fibonacci number via PHP

2018-11-01 00:00
54408   0
PHP, Test

Here is an example of Fibonacci numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...

Write a function f(x) so that return the following eg:

f(2) = 1 f(4) = 2 f(6) = 5 f(8) = 13 etc

And here is the code: function f($x = 0) { if ($x < 2) { return $x; } else { return f($x - 2) + f($x - 1); } }
Back « SMINT menu bar: fixed when scrolling

Leave a comment

Comments

Admin - 2015-01-20   0

nice php GD code to resize image: http://stackoverflow.com/questions/14649645/resize-image-in-php

Comment is closed

Category

Top Read

» SMINT menu bar: fixed when scrolling
» Finding the Nth Fibonacci number via PHP
» Screenfly / Test Your Website at Different Screen Resolutions

Top Tags

wiki, feature, bug, test, CMS, MySQL, blog, SIDU, forum, bank, ticket, news, PHP