Files
2025-04-14 13:22:47 +02:00

56 lines
1.8 KiB
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">
<link rel="stylesheet" href="style.css">
<title>Zadanie 3 - Średnia geometryczna</title>
</head>
<body>
<header>
<h1>Zadanie 3</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="block">
Napisz program, który dla czterech liczb rzeczywistych oblicza i wyświetla ich średnią geometryczną. Wynik wyświetl w dwóch postaciach. Bez zaokrąglenia oraz z zaokrągleniem do trzech miejsc po przecinku.
</div>
<div class="block">
<form action="index.php" method="post">
<label for="a">Podaj a:</label><br>
<input type="number" id="a" name="a" required><br>
<label for="b">Podaj b:</label><br>
<input type="number" id="b" name="b" required><br>
<label for="c">Podaj c:</label><br>
<input type="number" id="c" name="c" required><br>
<label for="d">Podaj d:</label><br>
<input type="number" id="d" name="d" required><br>
<input type="submit" value="Oblicz"><br>
</form>
</div>
<div class="block">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$d = $_POST['d'];
$srednia = pow($a * $b * $c * $d, 1/4);
$sredniaZaokraglona = round($srednia, 3);
echo <<<HEREDOC
<h3>Podane liczby:</h3>
<p>
A: $a <br>
B: $b <br>
C: $c <br>
D: $d <br>
<b>Średnia: $srednia</b> <br>
<b>Średnia zaokrąglona: $sredniaZaokraglona </b><br>
</p>
HEREDOC;
}
?>
</div>
</body>
</html>