FIBONACCI
36
<html>
<head>
<title><b>FIBONACCI SERIES</b></title>
</head>
<body>
<h1>FIBONACCI SERIES</h1>
<form method="post" action="">
<label for="terms">Enter the number of terms:</label>
<input type="number" name="terms" required>
<input type="submit" name="generate" value="Generate">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$terms = intval($_POST["terms"]);
if ($terms > 0) {
$a = 0;
$b = 1;
echo "<h2>The Answer is:</h2>";
echo $a;
for ($i = 1; $i < $terms; $i++) {
echo ',' . $b;
$next = $a + $b;
$a = $b;
$b = $next;
}
}
else {
echo "<p>Please enter a positive integer:</p>";
}
}
?>
</body>
</html>