Files
2025-10-31 22:15:27 +01:00

48 lines
1.4 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>Z90 - Podzielne przez K</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z90</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który dla podanej wartości zmiennej n i k wyświetla wszystkie liczby z przedziału <1, n> podzielne przez k.</p>
</div>
<div class="box">
<form action="index.php" method="post">
<fieldset>
<label for="n">Podaj N:</label>
<input type="number" name="n" id="n" required>
<label for="k">Podaj K:</label>
<input type="number" name="k" id="k" required>
</fieldset>
<button type="submit">Wyślij</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = htmlspecialchars($_POST['n']);
$k = htmlspecialchars($_POST['k']);
echo '<div class="box">';
$arr = array();
for ($i = 1; $i <= $n; $i++) {
if ($i % $k == 0) {$arr[] = $i;}
}
echo 'N = <b>' . $n . '</b><br>';
echo 'K = <b>' . $k . '</b><br>';
echo 'Liczby podzielne przez ' . $k . ' to : <b>' . implode(', ', $arr) . '</b>';
}
?>
</body>
</html>