PHP Forum

PHP Forum (http://www.selfphp.de/forum/index.php)
-   PHP Grundlagen (http://www.selfphp.de/forum/forumdisplay.php?f=12)
-   -   Lösung einer Gleichung (http://www.selfphp.de/forum/showthread.php?t=25762)

gustav 25.01.2016 10:03:21

Lösung einer Gleichung
 
PHP-Code:

<?php
          
        $a 
$_GET['a_eingabe'];
        
$b $_GET['b_eingabe'];        
        
$c $_GET['c_eingabe'];        
        
        
// Echo-Ausgabe nur zur Kontrolle
        // echo "<b>$a&sdot;x² + $b&sdot;x + $c  = 0</b>";
        
        
$det $b*$b-4*$a*$c;

        if (
$det <0)
        {
            echo 
"Die Gleichung $a&sdot;x² + $b&sdot;x + $c  = 0 hat keine Lösung.";
        }
        elseif (
$det ==0)
        {
            
$loesung round(-$b/(2*$a),2);
            echo 
"Die Gleichung $a&sdot;x² + $b&sdot;x + $c  = 0 hat die Lösung $loesung.";
        }
        elseif (
$det 0)
        {
            
$loesung1 round((-$b+sqrt($det))/(2*$a),2);
            
$loesung2 round((-$b-sqrt($det))/(2*$a),2);
            echo 
"Die Gleichung $a&sdot;x² + $b&sdot;x + $c  = 0 hat die Lösungen $loesung1 und $loesung2.";
        }

        
?>
        <p><a href="mitternacht_eingabe.html">Eine neue Gleichung berechnen?</a></p>


Domi 19.02.2016 12:59:41

AW: Lösung einer Gleichung
 
Hi Gustav,

vielen Dank für Deinen Vorschlag. Hast Du eine konkrete Frage dazu oder wolltest Du nur deine Lösung teilen?

Domi


Alle Zeitangaben in WEZ +2. Es ist jetzt 09:58:48 Uhr.

Powered by vBulletin® Version 3.8.3 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.