Created
December 11, 2012 17:38
-
-
Save AJ-Acevedo/4260530 to your computer and use it in GitHub Desktop.
Fibonacci Sequence using PHP
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Fibonacci Sequence using PHP</title> | |
</head> | |
<body> | |
<div align=center> | |
<h1>Fibonacci Sequence using PHP</h1> | |
</div> | |
<br> | |
<div id="fib"> | |
<?php | |
$a = 0; | |
$b = 1; | |
$c = $a + $b; | |
//echo the first 0, 1 of the sequence | |
echo $a . ", " . $b . ", "; | |
while ($c <= 4181) { | |
// if statement that adds ... instead of a , once the end of the sequence is reached. | |
echo "$c" . ( ($c == 4181) ? "..." : ", "); | |
$a = $b; | |
$b = $c; | |
$c = $a + $b; | |
} | |
?> | |
</div> | |
<p><br> | |
<p><?php echo '-------------------------------------------------------------------------------------------';?></p> | |
<p><a href="http://en.wikipedia.org/wiki/Fibonacci_number" title="Fibonacci Sequence on wikipedia">Fibonacci Sequence on wikipedia</a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment