Second degré

 avatar
unknown
php
5 months ago
812 B
9
Indexable
<!DOCTYPE html>
<html>
<head>
	<title>second degré</title>
	<meta charset="utf-8">
</head>
<body>
	<h1> Calcul du second degré</h1>
	<form method="post">
		a : <br>
		<input type="text" name="a"> <br/>
		b : <br>
		<input type="text" name="b"> <br/>
		c : <br>
		<input type="text" name="c"> <br/>
		<input type="submit" name="Valider" value="Valider">
	</form>
	<?php
	$a = $_POST["a"]; 
	$b = $_POST["b"]; 
	$c = $_POST["c"]; 

	$delta = $b * $b - 4 * $a * $c; 
	echo "Delta = $delta <br>";
	if ($delta < 0) {
		echo "Pas de solution"; 
	} else if ($delta == 0) {
		$x = -$b / (2 * $a); 
		echo "Une solution : $x"; 
	} else {
		$x1 = (-$b - sqrt($delta)) / (2 * $a); 
		$x2 = (-$b + sqrt($delta)) / (2 * $a); 
		echo "Deux solutions : $x1 et $x2"; 
	}
	?>
</body>
</html>
Editor is loading...
Leave a Comment