1. Computing & Technology

Discuss in my forum

Calculating the Hypotenuse in PHP

By , About.com Guide

See More About:

3 of 3

Using the Hypot () Function
Right Triangle

Right Triangle

Another way of calculating this is to use the Hypot () function. They Hypot function is written as hypot (num, num); with the first number being one side of the triangle (a) and the second number being the other side (b). It will output the hypotenuse. Here is an example of how to use it.
 <?php 
 $a = 3;
 $b = 4;
 $c = hypot ($a, $b);
 echo "a = " .$a. "<br>";
 echo "b = " .$b. "<br>";
 echo "c = " .$c. "<br>";
 ?> 

Again, with this script you can replace a and b with any values and it will calculate c.

  1. About.com
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Find the Hypotenuse with PHP - PHP Hypotenuse - Hypotenuse of a Right Triangle

©2012 About.com. All rights reserved.

A part of The New York Times Company.