Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions PHP/Nth Fibonacci Term.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

function Fibonacci($number)
{

// if and else if to generate first two numbers
if ($number == 0)
return 0;
else if ($number == 1)
return 1;

// Recursive Call to get the upcoming numbers
else
return (Fibonacci($number-1) +
Fibonacci($number-2));
}

// Taking Nth term to be 10 by default - can be changed
$n = 10;

// Below line can be used to input n's value from console
// $n = intval(readline('Enter the value of N : '));

echo "<h3>Nth term of the Fibonacci series is : </h3>";
echo "\n";

// Calling recursive function to calculate and
// print Nth term of the Fibonacci Series
echo Fibonacci($n);

?>