22. PHP Program to find Area of triangle if three sides are given.
How does this program work?
- In this program you are going to learn about how to find out the Area of triangle if three sides are given using PHP.
- In this program to take user inputs three values for the given Triangle. And these three values can be store in three different variables.
- 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 a value"/> </td>
</tr>
<tr>
<td> <input type="text" name="num2" value="" placeholder="Enter b value"/> </td>
</tr>
<tr>
<td> <input type="text" name="num3" value="" placeholder="Enter c value"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$a = $_POST['num1'];
$b = $_POST['num2'];
$c = $_POST['num3'];
// Compute s //
$s = ($a + $b + $c) / 2;
$area = sqrt($s * ($s - $a) * ($s - $b) * ($s - $c)); //Formula for area of the triangle
$precision = 4;
echo " Area of the trainagle is = ".number_format($area, $precision);
return 0;
}
?>
</body>
</html>