Posted on January 26th, 2010
4707 views Hi everyone, � Today I'm going to demonstrate how to use php to do all your pythagoras homework with one simple script. � As I'm sure you know, the formula for pythagoras is: � c2=a2 + b2 � so here's the script. � � <center<h1>Finding the Hypotenuse</h1> <?php if($_POST['Submit']) { $num1 = $_POST['num1']; $num2 = $_POST['num2']; $sqrd1 = $num1*$num1; //the squared number $sqrd2 = $num2*$num2; //the squared number $sumof = $sqrd1+$sqrd2; //the sum of the squared number $answer = sqrt($sumof); //the answer //below is the working for you to copy out. echo("The answer is " . $ans . ". <br /> Working: <br /> a� = b� + c� <br /> a� = " . $num1 . "� + " . $num2 . "�<br /> a� = " . $sqrd1 . " + " . $sqrd2 . "<br /> a� = " . $sumof . "<br /> a = √" . $sumof . "<br /> a = $answer <br />" ); } ?> //the form to get the input variables <form method="post" action="index.php" name="Submit"> Number 1<input type="text" name="num1" /><br /> Number 2<input type="text" name="num2" /><br /> <input type="submit" name="Submit" value="Submit"/> </form> </center> � |