Skip to content Skip to sidebar Skip to footer

Create A Mechanism To Pass In A Positive Integer And Display All The Values Of The Fibonacci Series Up To And Including The Specified Value

Copy

After this loop, the $max var is equal to 5^$powerof, which is not what you want. Just remove this part and it should work fine.

Also change your test from

while ($z < $max) {

to

while ($z <= $max) {

if you want to include the maximum value.

Solution 2:

<labelfor="powerof">Fibonacci: </label><inputtype="text"name="powerof"value="<?phpecho$_GET['powerof']; ?>"/><inputtype="submit"name='Go'value="Calculate" /></fieldset></form><?php$message = 'The fibonacci sequence is: <br />1<br />2<br />';
$powerof = 0;
$max = 10;
$temp = $max;

if (isset($_GET['powerof'])) {
    $powerof = $_GET['powerof'];
}

if ($powerof > 100) {
    $powerof = 100;
    $message = 'Sorry, your input was too high. I converted it to the maximum value of 100.<br />The fibonacci sequence is: <br />1<br />2<br />';

}

$x = 0;
$y = 1;
$z = 0;
$counter = 0;

while ($counter < $powerof) {
    if ($counter <= 1) {
        $z = 1;
    } else {
        $z = $x + $y;
    }
    echo($z."<br />"); 
    $x = $y;
    $y = $z;
    $counter++;
}

?>

this is the working version

Post a Comment for "Create A Mechanism To Pass In A Positive Integer And Display All The Values Of The Fibonacci Series Up To And Including The Specified Value"