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.
Result of php executing
Full code of a^2 + b^2 = c^2.php
- <?php
- /* EDIT BELOW THIS LINE */
- $a = "4";
- $b = "4";
- /* EDIT ABOVE THIS LINE */
- if(!is_numeric($a)) { no_input(); } else { find_c(); }
- function find_c() {
- global $a, $b;
- if (!is_numeric($b)) { no_input(); } else {
- $a2 = $a ** 2;
- $b2 = $b ** 2;
- $a2b2 = $a2 + $b2;
- $c_raw = sqrt($a2 + $b2);
- $c_round = round($c_raw, 1);
- echo "Equation: a^2 + b^2 = c^2\r\n";
- echo "Equation: $a^2 + $b^2 = c^2\r\n";
- echo "Equation: $a2 + $b2 = c^2\r\n";
- echo "Equation: $a2b2 = c^2\r\n";
- echo "Equation: √($a2b2) = c^2\r\n";
- echo "Equation: $c_raw = c\r\n";
- echo "Equation: ~$c_round = c\r\n";
- echo "Equation: c = $c_round\r\n\r\n";
- echo "The hypotenuse of the right triangle is $c_round. (Raw Answer: $c_raw)\r\n";
- echo "Sides a and b were both defined.\r\n";
- echo "Variables: a = $a, b = $b, c rounded = $c_round, c raw = $c_raw)";
- exit();
- }
- }
- function no_input() {
- echo "Equation: ERR + ERR = ERR\r\n";
- echo "The hypotenuse is unable to be determined.\r\n";
- echo "Sides a nor b were defined.\r\n";
- echo "Make sure you entered in both variables.\r\n";
- exit();
- }
- ?>
File Description
- a^2 + b^2 = c^2
- PHP Code
- 15 Feb-2018
- 1.21 Kb
You can Share it:
Latest PHP Pastes