-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Fibonacci_Number.php * Update Fibonacci_Number.php * Update Fibonacci_Number.php * Update Fibonacci_Number.php
- Loading branch information
1 parent
89bd031
commit 889356f
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/*A series of numbers in which each number is the sum of the two preceding numbers. Eg : 1, 1, 2, 3, 5, 8, etc. */ | ||
function FibonacciNum($num){ | ||
|
||
if ($num == 0) | ||
return 0; | ||
else if ($num == 1) | ||
return 1; | ||
else | ||
return (FibonacciNum($num-1) + | ||
FibonacciNum($num-2)); | ||
} | ||
|
||
//Driver Program - | ||
$num = 6; | ||
for ($count = 0; $count < $num; $count++){ | ||
echo FibonacciNum($count),' '; | ||
} | ||
|
||
/* | ||
Input : | ||
6 | ||
Output : | ||
The fibonacci number at position 6 is 8 | ||
Fibonacci series: | ||
1 1 2 3 5 8 | ||
*/ | ||
|
||
?> |