a^2 + b^2 = c^2 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of a^2 + b^2 = c^2.php

  1. <?php
  2.     /* EDIT BELOW THIS LINE */
  3.       $a = "4";
  4.       $b = "4";
  5.     /* EDIT ABOVE THIS LINE */
  6.     if(!is_numeric($a)) { no_input(); } else { find_c(); }
  7.       function find_c() {
  8.           global $a, $b;
  9.           if (!is_numeric($b)) { no_input(); } else {
  10.         $a2 = $a ** 2;
  11.         $b2 = $b ** 2;
  12.         $a2b2 = $a2 + $b2;
  13.         $c_raw = sqrt($a2 + $b2);
  14.         $c_round = round($c_raw, 1);
  15.     echo "Equation: a^2 + b^2 = c^2\r\n";
  16.     echo "Equation: $a^2 + $b^2 = c^2\r\n";
  17.     echo "Equation: $a2 + $b2 = c^2\r\n";
  18.     echo "Equation: $a2b2 = c^2\r\n";
  19.     echo "Equation: √($a2b2) = c^2\r\n";
  20.     echo "Equation: $c_raw = c\r\n";
  21.     echo "Equation: ~$c_round = c\r\n";
  22.     echo "Equation: c = $c_round\r\n\r\n";
  23.     echo "The hypotenuse of the right triangle is $c_round. (Raw Answer: $c_raw)\r\n";
  24.     echo "Sides a and b were both defined.\r\n";
  25.     echo "Variables: a = $a, b = $b, c rounded = $c_round, c raw = $c_raw)";
  26.     exit();
  27.           }
  28. }
  29.     function no_input() {
  30.         echo "Equation: ERR + ERR = ERR\r\n";
  31.         echo "The hypotenuse is unable to be determined.\r\n";
  32.         echo "Sides a nor b were defined.\r\n";
  33.         echo "Make sure you entered in both variables.\r\n";
  34.         exit();
  35.     }
  36. ?>
File Description
  • a^2 + b^2 = c^2
  • PHP Code
  • 15 Feb-2018
  • 1.21 Kb
You can Share it: