Files
2p_pracownia_programowania_php/Zadania/Z75 - liczby fibonacciego iter/index.php
2025-10-29 09:29:54 +01:00

54 lines
1.5 KiB
PHP

<?php
?>
<!doctype html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Z75a - Liczby Fibonacciego iteracyjnie</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z75a</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który dla danej liczby całkowitej n wypisuje wyrazy ciągu Fibonacciego według zależności</p>
<img src="075.png" alt="Zależność Fibonacciego">
<p>Dla n=20 program powinien wypisać: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765</p>
</div>
<div class="box">
<form action="index.php" method="post">
<label for="n">Podaj Liczbę N:</label>
<input type="number" name="n" id="n">
<button type="submit">Wyślij</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = htmlspecialchars($_POST['n']);
echo '<div class="box">';
if ($n == 0) {
echo 'F(0) = 0';
} else if ($n == 1) {
echo 'F(1) = 1';
} else {
$a = 0;
$b = 1;
$out = 0;
for ($i = 0; $i <= $n; $i++) {
$out = $a;
[$a, $b] = [$b, $a + $b];
echo 'F(' . $i . ') = ' . $out . '<br>';
}
}
echo '</div>';
}
?>
</body>
</html>