21. PHP Program to find Area of the triangle using Base and Height values.
How does this program work?
- In this program you are going to learn about how to find out the Area of triangle using PHP.
- In this program to take user inputs base and height values for the given Triangle.
- After that by using area of triangle formula we can get the Output.
Here is the code
<html>
<head>
<title>PHP Program To determine the area of triangle</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num1" value="" placeholder="Enter base of triangle"/>
</td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter height of triangle"/>
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$b = $_POST['num1'];
$h = $_POST['num2'];
$area = ($b*$h)/2; //Formula for area of trainagle
$precision = 2;
echo " Area of the trainagle is = ".number_format($area, $precision);
return 0;
}
?>
</body>
</html>