Files
2025-10-23 08:43:51 +02:00

60 lines
1.9 KiB
PHP

<?php
$text = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$delta = $b * $b - 4 * $a * $c;
if ($delta < 0) {
$text = 'Równanie nie ma rozwiązanie';
} else if ($delta == 0) {
$x1 = -$b / (2 * $a);
$text = 'Równanie ma jedno rozwiązanie: x = ' . $x1;
} else if ($delta > 0) {
$x1 = (-$b + sqrt($delta)) / (2 * $a);
$x2 = (-$b - sqrt($delta)) / (2 * $a);
$text = 'Równanie ma dwa rozwiązania: x1 = ' . $x1 . ' i x2 = ' . $x2;
}
}
?>
<!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>Z65 - Równanie kwadratowe</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z65</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
<p>Napisz program, który oblicza pierwiastki równania kwadratowego. Program dla danych A, B i C ma sprawdzać czy równanie jest kwadratowe, czy ma jeden czy dwa pierwiastki i czy ma rozwiązanie.</p>
</div>
<div class="box">
<form action="index.php" method="post">
<label for="a">Wprowadź A: </label><br>
<input type="number" name="a" id="a"><br>
<label for="b">Wprowadź B:</label><br>
<input type="number" name="b" id="b"><br>
<label for="c">Wprowadź C:</label><br>
<input type="number" name="c" id="c"><br>
<button type="submit">Wyślij</button>
</form>
</div>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<div class="box">' . "A: <b>$a</b><br>B: <b>$b</b><br>C: <b>$c</b><br> ";
echo "Postać równania: <b>$a * x<sup>2</sup> + $b * x + $c = 0</b><br>";
echo $text . '</div>';
}
?>
</body>
</html>