Write a program to determine whether a triangle is isosceles or not?
<!DOCTYPE html>
<html>
<head>
<title>Isosceles Triangle Checker</title>
</head>
<body>
<h2>Check if the Triangle is Isosceles</h2>
<form method=”post”>
Side A: <input type=”number” name=”a” required><br><br>
Side B: <input type=”number” name=”b” required><br><br>
Side C: <input type=”number” name=”c” required><br><br>
<input type=”submit” value=”Check Triangle”>
</form>
<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
// Get side values
$a = $_POST[‘a’];
$b = $_POST[‘b’];
$c = $_POST[‘c’];
// First check if it can form a triangle
if ($a + $b > $c && $a + $c > $b && $b + $c > $a) {
// Now check if any two sides are equal
if ($a == $b || $b == $c || $a == $c) {
echo “<h3>Yes, it’s an Isosceles Triangle.</h3>”;
} else {
echo “<h3>No, it’s not an Isosceles Triangle.</h3>”;
}
} else {
echo “<h3>The given sides do not form a valid triangle.</h3>”;
}
}
?>
</body>
</html>
Output


How it Works:
- User inputs three side lengths.
- PHP first checks if a triangle can be formed using the triangle inequality rule.
- Then it checks if any two sides are equal.
- Displays whether it is isosceles or not.