Area of a triangle is calculated by the following Mathematical formula,
(base * height) / 2 = Area
Program:
Program to calculate area of triangle with base as 10 and height as 15 is shown.
<?php
$base = 10;
$height = 15;
echo "Area of Triangle having base $base and height $height= " . ($base * $height) / 2;
?>
Output:
Area of Triangle with Form
Program to calculate area of triangle by inserting values in the form is shown.
<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 as $height is $area";
}
?>
Output:
Read more:
The Tech Platform
Comments