Publishing System Settings Logout Login Register
Using Pythagoras in PHP
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on January 26th, 2010
4707 views
PHP Coding

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 = &#8730;" . $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>

Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
chironic

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top