Home >>PHP Programs >PHP Program to find the area of a given triangle

PHP Program to find the area of a given triangle

PHP Program to find the area of a given triangle

In this example, we will create a PHP program to find the area of a given triangle.

The Mathematical formula to calculate the Area of a triangle is,

Area = (base * height) / 2 
Program to Find Aread of triangle Example 1

<?php  
$base = 15;  
$height = 25;  
echo "area with base $base and height $height= " . ($base * $height) / 2;  
?> 

Output:-
area with base 15 and height 25= 187.5
Program to Find Aread of triangle Example 2

<?php 
extract($_REQUEST);
if(isset($calculate))
{
echo "area with base $base and height $height= " . ($base * $height) / 2;
}
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Form</title>
	</head>
	<body>
		<form method="post">
		<table>
		<tr>
		<td>Enter Your Base</td>
		<td><input type="text" name="base" required/></td>
		</tr>
		<tr>
		<td>Enter Your Height</td>
		<td><input type="text" name="height" required/></td>
		</tr>
		<tr>
		<td colspan="2" align="center">
			<input type="submit" value="Calculate Aread" name="calculate"/>
		</tr>
		</form>
	</body>
</html>

Output:-
Find area of Traiange

No Sidebar ads