Files
2p_pracownia_programowania_php/Zadania/Z37 - wartość bezwzględna/index.php
2026-01-13 00:24:42 +01:00

44 lines
1.1 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>Z37 - Wartość bezwzględna</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z37</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który dla liczby A oblicza jej wartość bezwzględną (nie używaj wbudowanej funkcji matematycznej).</p>
</div>
<div class="box">
<form action="index.php" method="post">
<fieldset>
<label for="a">Wartość A:</label>
<input type="number" name="a" id="a">
</fieldset>
<button type="submit">Wyślij</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$a = htmlspecialchars($_POST['a']);
echo "<div class='box'>";
echo "A = {$a}<br>";
if ($a < 0) {
$a = -$a;
}
echo "Wartość bezwzględna liczby A: {$a}";
echo '</div>';
}
?>
</body>
</html>