Files
2p_pracownia_programowania_php/Zadania/Z85 - n pseudolosowych/index.php
2025-10-31 22:15:27 +01:00

54 lines
1.6 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>Z85 - N Pseudolosowych</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z85</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który dla trzech liczb całkowitym n, min, max wyświetla n liczb pseudolosowych z zakresu <min, max>.</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="min">Podaj Min:</label>
<input type="number" name="min" id="min" required>
<label for="max">Podaj Max:</label>
<input type="number" name="max" id="max" required>
</fieldset>
<button type="submit">Wyślij</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$n = htmlspecialchars($_POST['n']);
$min = htmlspecialchars($_POST['min']);
$max = htmlspecialchars($_POST['max']);
echo '<div class="box">';
if ($n > 0 && $min < $max) {
echo 'Wylosowane liczby: <b>';
for ($i = 0; $i < $n; $i++) {
echo rand($min, $max) . ', ';
}
echo '</b>';
} else {
echo 'N jest mniejsze od 0 lub max jest mniejsze od min';
}
echo '</div>';
}
?>
</body>
</html>