PHP 三角形的面积
三角形的面积可以通过以下数学公式计算:
(base * height) / 2 = Area
PHP中的三角形面积
显示以底为10和高为15的三角形面积计算程序。
示例:
<?php
base = 10;height = 15;
echo "area with base base and heightheight= " . (base *height) / 2;
?>
输出:
PHP中使用表单计算三角形的面积
展示了通过在表单中插入数值来计算三角形面积的程序。
示例:
<html>
<body>
<form method = "post">
Base: <input type="number" name="base">
<br><br>
Height: <input type="number" name="height"><br>
<input type = "submit" name = "submit" value="Calculate">
</form>
</body>
</html>
<?php
if(isset(_POST['submit']))
{base = _POST['base'];height = _POST['height'];area = (base*height) / 2;
echo "The area of a triangle with base as base and height asheight is $area";
}
?>
输出: