Calculate Right Triangle Hypotenuse in PHP
This Snippet is coded by a user inOnline php Compiler. You can see and run this code too.
زبان: PHP
This PHP code defines a function hypotenuse that calculates the length of the hypotenuse of a right-angled triangle given the lengths of the other two sides ($a and $b). It uses the Pythagorean theorem: c = sqrt(a² + b²).
To use it, call the function with two numeric arguments representing the legs of the triangle. For example:
echo hypotenuse(3, 4); // outputs 5
The function returns the hypotenuse as a float. You can then output it or use it in further calculations.