Program to find area of an isosceles triangle
- Write a program to find area of isosceles triangle in C
- Write a program to find area of isosceles triangle in C++
- Write a program to find area of isosceles triangle in Python
- Write a program to find area of isosceles triangle in PHP
- Write a program to find area of isosceles triangle in Java
- Write a program to find area of isosceles triangle in Java Script
- Write a program to find area of isosceles triangle in C#
Explanation:
A triangle with two equal-length sides is called an isosceles triangle. The third side is referred to as the base, and these equal sides are known as the legs. Equal sides have equal angles on the other side.
Key Characteristics:
- Two Equal Sides: Two of the three sides of the triangle are of the same length.
- Two Equal Angles: The angles opposite the equal sides are congruent (same measure).
- Symmetry: An isosceles triangle is symmetric along the line that bisects the base and passes through the vertex angle.
Types of Isosceles Triangles:
- Acute Isosceles Triangle: All angles are less than 90o.
- Right Isosceles Triangle: One of the angles is 90o, making it a right triangle with two equal legs.
- Obtuse Isosceles Triangle: One of the angles is greater than 90o.
Formulae for Isosceles Triangle:
- Area: Area = 0.5 × Base × Height,
- or, if sides are known: Area = Base/4 × sqrt(4a2 – Base2)
- Perimeter: Perimeter = 2a + Base
Where aaa is the length of the equal sides.
Program to find area of an isosceles triangle
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> #include <math.h> int main() { float base, side, area; printf("Enter the base of the isosceles triangle: "); scanf("%f", &base); printf("Enter the equal side of the isosceles triangle: "); scanf("%f", &side); if (2 * side > base) { area = (base * sqrt(4 * side * side - base * base)) / 4; printf("Area of the isosceles triangle: %.2f\n", area); } else { printf("Invalid dimensions! The base should be smaller than twice the side length.\n"); } return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double base, side, area; cout << "Enter the base of the isosceles triangle: "; cin >> base; cout << "Enter the equal side of the isosceles triangle: "; cin >> side; if (2 * side > base) { area = (base * sqrt(4 * side * side - base * base)) / 4; cout << "Area of the isosceles triangle: " << area << endl; } else { cout << "Invalid dimensions! The base should be smaller than twice the side length." << endl; } return 0; }
import math base = float(input("Enter the base of the isosceles triangle: ")) side = float(input("Enter the equal side of the isosceles triangle: ")) if 2 * side > base: area = (base * math.sqrt(4 * side**2 - base**2)) / 4 print(f"Area of the isosceles triangle: {area:.2f}") else: print("Invalid dimensions! The base should be smaller than twice the side length.")
<?php echo "Enter the base of the isosceles triangle: "; $base = (float)readline(); echo "Enter the equal side of the isosceles triangle: "; $side = (float)readline(); if (2 * $side > $base) { $area = ($base * sqrt(4 * $side * $side - $base * $base)) / 4; echo "Area of the isosceles triangle: " . number_format($area, 2) . "\n"; } else { echo "Invalid dimensions! The base should be smaller than twice the side length.\n"; } ?>
import java.util.Scanner; public class IsoscelesTriangleArea { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the base of the isosceles triangle: "); double base = scanner.nextDouble(); System.out.print("Enter the equal side of the isosceles triangle: "); double side = scanner.nextDouble(); if (2 * side > base) { double area = (base * Math.sqrt(4 * side * side - base * base)) / 4; System.out.printf("Area of the isosceles triangle: %.2f\n", area); } else { System.out.println("Invalid dimensions! The base should be smaller than twice the side length."); } scanner.close(); } }
const base = parseFloat(prompt("Enter the base of the isosceles triangle:")); const side = parseFloat(prompt("Enter the equal side of the isosceles triangle:")); if (2 * side > base) { const area = (base * Math.sqrt(4 * side * side - base * base)) / 4; console.log(`Area of the isosceles triangle: ${area.toFixed(2)}`); } else { console.log("Invalid dimensions! The base should be smaller than twice the side length."); }
using System; class Program { static void Main() { Console.Write("Enter the base of the isosceles triangle: "); double baseLength = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter the equal side of the isosceles triangle: "); double side = Convert.ToDouble(Console.ReadLine()); if (2 * side > baseLength) { double area = (baseLength * Math.Sqrt(4 * side * side - baseLength * baseLength)) / 4; Console.WriteLine($"Area of the isosceles triangle: {area:F2}"); } else { Console.WriteLine("Invalid dimensions! The base should be smaller than twice the side length."); } } }