Untitled - PHP 2.41 KB
                                
                                    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action= "index.php" method = "POST">
        <p> a: <input type = "text" name = "a" ></p>
        <p> b: <input type = "text" name = "b" ></p>
        <p> c: <input type = "text" name = "c" ></p>
        <input type = "submit" value = "Delta">
    </form>
        <?php
              function pierwiwastki ($a, $b, $c, $x1, $x2)
            {
                $d = delta($a, $b, $c);
                if($d < 0)
                {
                    return 0;
                }
                else if($d == 0)
                {
                    $x1 = $x2 = -$b / (2 *$a);
                    return 1;
                }
                else
                {
                    $x1 = (-$b + sqrt($d))/(2 * $a);
                    $x1 = (-$b - sqrt($d))/(2 * $a);
                    return 2;
                }
            }
              
            
            
            if($_POST)
            {
                $a = $_POST["a"];
                $b = $_POST["b"];
                $b = $_POST["c"];
               
                %x1 = 0;
                $x2 = 0;
                $ile = pierwiwastki($a, $b, $c, $x1, $x2);

                if($ile == 0)
                {
                    echo "Funkcja nie ma pierwiastków";
                }
                else if$ile == 1)
                {
                    echo "<br> Mamy jeden podwójny pierwiastek: $x1";
                }
                else if($ile == 2)
                {
                    echo "<br> Mamy dwa pierwiastki";
                    echo "<br> x1 = $x1";
                    echo "<br> x2 = $x2";
                } 
            }
            
        ?>
</body>
</html>
                                
                            

Paste Hosted With By Wklejamy.pl